V20PCA204 - Android Application Development

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 32

PART A –

10 questions, each carrying 1 mark per unit. [50 MCQ's with answers]
1. What is splash screen in android?
A - Initial activity of an application
B - Initial service of an application
C - Initial method of an application
D - Initial screen of an application
Correct Answer: D
2. What is JSON in android?
A - Java Script Object Native
B - Java Script Oriented Notation
C - Java Script Object Notation
D - None of the Above
Correct Answer: C
3. What is an interface in android?
A - Interface acts as a bridge between class and the outside world.
B - Interface is a class.
C - Interface is a layout file.
D - None of the above
Correct Answer: A
4. Android Is Developed by

A - Apple.
B - Samsung.
C - Google
D - AndroidInc
Correct Answer: D
5. Android web browser is based on
A - Chrome
B – Open Source web kit.
C - Google
D – Firebox
Correct Answer: B
6. Parent class of Activity?

A ) object
B ) context
C ) activityGroup
D ) contextThemeWrapper
Correct Answer: D
7. Which are the screen densities in Android?

A) low density
B) medium density
C) extra high density
D) all of the above
Correct Answer: D
8. Which are the screen sizes in Android?

A) small
B) normal
C) large
D) all of the above
Correct Answer: D
9. Layouts in android?

A) Frame Layout
B) Linear Layout
C) Relative Layout
D) All of the above
Correct Answer: D
10. Creating a UI (User Interface) in Android requires careful use of…

A ) Java and SQL


B ) XML and Java
C ) XML and C++
D ) Dream weaver
Correct Answer: B
11. What year was the Open Handset Alliance announced?

A ) 2005
B ) 2006
C ) 2007
D ) 2008
Correct Answer: C
12. What file is responsible for glueing everything together, explaining what the application
consists of, what its main building blocks are, ext.…?

A ) Layout file
B ) Strings XML
C ) R file
D ) Manifest file
Correct Answer: D
13.Android Software Package is based on
A) Linux OS
B) Windows OS
C) Mac OS
D) None of these
Correct Answer: A
14.Full form of OHA
A) Open Hand Application
B) Open Handset Alliance
C) Open Handset Application
D) Out Handset Alliance
Correct Answer: B
15.Full form of DVM
A) Dell Virtual Model
B) Dev virtual machine
C) Dalvik virtual machine
D) Dalvik virtual Model
Correct Answer: C
16.What does the .apk extension stand for?

A ) Application Package
B ) Application Program Kit
C ) Android Proprietary Kit
D ) Android Package
Correct Answer: A
17.The ___________ file specifies the layout of your screen?

A ) Layout file
B ) Manifest file
C ) Strings XML
D ) R file
Correct Answer: A
18.When developing for the Android OS, Java byte code is compiled into what?

A ) C++ source code


B ) Python application code
C ) Dalvik byte code
D ) C source code
Correct Answer: C
19.What built-in database is Android shipped with?

▪ A ) SQLite
B ) Apache
C ) MySQL
D ) Oracle
Correct Answer: A
20.What is contained within the manifest xml file?

A ) The permissions the app requires


B ) The list of strings used in the app
C ) The source code
D ) All other choices
Correct Answer: A

21.What is the name of android version Android 4.1 – 4.3


a) Jelly Bean
b) KitKat
c) Lollipop
d) None
Correct Answer: A
22.What is the version name of API Level26
a) Lollipop
b) Oreo
c) Honeycomb
d) Android 10
Correct Answer: B
23.The original Linux kernel was developed in
a) 1991
b) 1992
c) 1993
d) 1994
Correct Answer: A

24.What does the ART stands for?


a) Android Running tune
b) App Runtime
c) Android Runtime
d) None of these
Correct Answer: C

25. What does the JIT & VM stands for?


a) Just-in-time & Virtual Machine
b) Jit& Virtual Machine
c) Just-in-time
d) None of these
Correct Answer: C
26. Working with low-level 2D graphics drawing API including colors, points, filters,
rectangles and canvases.
a) Android.3d
b) android.app
c) android.graphics
d) None of these
Correct Answer: C
27. Provides classes to enable playback of audio and video
a) Android.3d
b) android.app
c) android.graphics
d) None of these
Correct Answer: C
28. It is a view group that aligns all children in a single direction, vertically or
horizontally?
a) Linear Layout
b) Relative Layout
c) Table Layout
d) List View
Correct Answer: A
29. It is an integrated development environment (IDE) for developing applications using
the Java programming language and other programming languages
a) Eclipse
b) Java
c) XML
d) List View
Correct Answer: A
30. To Check your project status
a) Toolbar
b) Status bar
c) Navigation bar
d) Tool Window bar
Correct Answer: B

31. It is open-source.Anyone can customize its Platform


A. Windows
B. Android
C. All Software
D. None of these
Correct Answer: B
32. There are many code names of android such as
A. Sandwich
B. Lollipop
C. KitKat
D. All of above
Correct Answer: D
33. OHA was established on
A. 5th November, 2017
B. 15th November, 2007
C. 5th November, 2007
D. None of these
Correct Answer: C
34. Which one is latest version of Android
A. 10.0
B. 9.0
C. 8.1
D. None of these
Correct Answer: A
35. Android is based on Linux for the following reason.
A. Security
B. Portability
C. Networking
D. All of these
Correct Answer: D

36. Which among the following are part of "Application" layer of Android Architecture?
A. Contacts
B. Browser
C. Phone
D. All of these
Correct Answer: D
37. What does the src folder contain?
A. Image and icon files
B. XML resource files
C. The application manifest file
D. Java source code files
Correct Answer: D

38. The android library that provides access to UI pre-built elements such as buttons, lists,
views etc. is
A. android.text
B. android.os
C. android.webkit
D. android.view
Correct Answer: C
39. What was the first phone released that ran the Android OS?
A. Google gPhone
B. T-Mobile G1
C. Motorola Droid
D. HTC Hero
Correct Answer: B
40. During an Activity life-cycle, what is the first callback method invoked by the system?
A. onStop()
B. onStart()
C. onCreate()
D. onRestore()
Correct Answer: C

41. The SQLite database management system is an ____ database.

A. Embedded relational
B. Non-embedded relational
C. Non-relational
D. Structural

Correct Answer: A) Embedded relational

42. An ____, self-contained, stand-alone, transactional relational database engine,


SQLite is designed to be embedded within an application without requiring additional
configuration.

A. Open-source
B. Closed-source
C. Open-end
D. Open-wire

Correct Answer: A) Open-source

43. In SQLite, files are ____ directly to disk.

A. Read
B. Written
C. Both A and B
D. None of the above

Correct Answer: C) Both A and B

44. Typically, a single disk file contains the entire SQL database, including ____ and
views.

A. Tables
B. Indices
C. Triggers
D. All of the above

Correct Answer: D) All of the above

45. SQLite is a ____ database resource.

A. Interface
B. Non-interface
C. Portable
D. Non-portable

Correct Answer: C) Portable

46. For your programming language to access that database, you'll need an SQLite
____.

A. Powerplug
B. Extension
C. Structure
D. Database

Correct Answer: B) Extension

47. What is/are the feature(s) of SQLite?

A. Totally free
B. Serverless
C. Very flexible
D. All of the above

Correct Answer: D) All of the above

48. Which of the following layout in android aligns all children either vertically or
horizontally?

a. RelativeLayout
b. TableLayout
c. FrameLayout
d. LinearLayout

Correct Answer: D) LinearLayout

49. Which of the following class in android displays information for a short period of time
and disappears after some time?

a. toast class
b. log class
c. maketest class
d. None of the above

Correct Answer: A) toast class

50 . Explain android activity life cycle?

A. onCreate() −> onStart() −> onActivityStarted() −> onResume() −> onPause() −>
onStop() −> onActivityDistroy() −> onDestroy()
B. OnCreate() −> onStart() −>onResume() −> onPause() −> onStop() −> onRestart() −>
onDestroy()
C. OnCreate() −> onStart() −> onPause() −> onResume() −> onStop() −> onDestroy()-
−>onResume()
D. All of the above

Correct Answer: B

1. Android Architecture:
o Describe the components of Android architecture and their roles.
o Explain the interaction between different layers of Android architecture.
o Discuss the importance of Linux Kernel, Android Runtime, and Application
Framework in Android system.

2. Activity Lifecycle:
o Draw and explain the lifecycle diagram of an Android activity.
o Describe each method in the activity lifecycle with its purpose.
o How does the activity lifecycle affect the behavior of an Android application?

3. User Interface Components:


o Explain the usage of ListView and RecyclerView in Android applications.
o Compare and contrast between LinearLayout, RelativeLayout, and
ConstraintLayout.
o Discuss the significance of Fragments in Android UI design.

4. Android Manifest and Gradle Build System:


o Describe the purpose of AndroidManifest.xml in an Android application.
o Discuss the structure and key components of the AndroidManifest.xml file.
o Explain the role of the build.gradle file in an Android project.
o What are dependencies and how are they managed in Android using Gradle?

5. Android Components:
o Define and differentiate between activities, services, broadcast receivers, and
content providers.
o Explain when and why each Android component type is used in application
development.
o How are intents used to communicate between components in Android?

6. Data Storage and Networking:


o Compare SQLite and SharedPreferences for local data storage in Android.
o Discuss the usage of AsyncTask and AsyncTaskLoader in managing
background tasks.
o Explain how Retrofit library is used for network requests in Android.

7. Security and Permissions:


o Describe the importance of permissions in Android applications.
o Explain how to request and handle runtime permissions in Android.
o Discuss strategies to secure data transmission over networks in Android.

8. Handling User Input and UI Events:


o Explain how to handle button clicks and other UI events in Android.
o Discuss the role of listeners and adapters in Android UI programming.
o How can you implement validation and error handling in Android forms?

9. Advanced Topics:
o Discuss the implementation of Google Maps API in an Android application.
o Explain how to use sensors (e.g., accelerometer, GPS) in Android
development.
o Describe the MVVM architecture and how it can be implemented in Android
using ViewModel and LiveData.

10. Testing and Debugging:


o Explain different approaches to testing Android applications (e.g., unit testing,
UI testing).
o Describe common debugging techniques and tools used in Android
development.
o How can you optimize an Android application for performance and battery
efficiency?
PART B
5 questions, each carrying max. 5 marks per unit with answers [Total 25 Questions]

1. What is the Android OS? Explain OHA.


● The Android OS is a mobile operating system developed by Google, based on
the Linux kernel. It is designed primarily for touchscreen mobile devices such
as smartphones and tablets. Android provides a rich application framework
that allows developers to create innovative apps for various purposes.
● OHA stands for Open Handset Alliance, which is a consortium of technology
companies led by Google. The OHA aims to develop open standards for
mobile devices and promote the Android platform. Members of the OHA
collaborate on the development and enhancement of Android, ensuring its
openness and compatibility across different devices and manufacturers.
2. Explain about various Layouts in Android.
● Layouts in Android are used to arrange UI components in a user interface.
Some common layouts include:
● LinearLayout: Arranges components in a single row or column.
● RelativeLayout: Positions components relative to each other or the
parent layout.
● FrameLayout: Places components on top of each other, allowing for
layering.
● ConstraintLayout: Allows for complex layouts by defining constraints
between components.
● GridLayout: Arranges components in a grid-like fashion with rows and
columns.
3. Write code of intent to move from one page to another in android.
Intent intent = new Intent(this, SecondActivity.class);
startActivity(intent);.class); startActivity(intent);
4. What is the working of Android Manifest file? Also Explain the elements of
Manifest.
● The AndroidManifest.xml file provides essential information about an
Android app to the Android system. It includes details about the app's
components, permissions, and metadata required by the system for proper
execution.
● Some key elements of the AndroidManifest.xml file include:

● <application>: Defines the application and its components.


● <activity>: Describes an activity within the application.
● <service>: Declares a service that performs background tasks.
● <receiver>: Specifies a broadcast receiver component.
● <provider>: Defines a content provider component.
● <uses-permission>: Declares the permissions required by the app.
5. List and explain the challenges of Android app development?
● Fragmentation: Variability in screen sizes, resolutions, and hardware
configurations across devices.
● Platform Fragmentation: Different versions of the Android OS in use
simultaneously, leading to compatibility issues.
● Device Compatibility: Ensuring the app works across various devices with
different hardware capabilities.
● Security Concerns: Protecting user data and preventing vulnerabilities like
malware and unauthorized access.
● User Interface Design: Designing interfaces that are intuitive and adaptable to
different screen sizes and orientations.

6. Explain the Android app build process?


● The Android app build process involves several steps:
● Compilation: Source code written in Java or Kotlin is compiled into
bytecode.
● Resource Processing: XML layout files, images, and other resources
are processed and packaged.
● APK Packaging: All compiled code, resources, and manifest files are
bundled into an APK (Android Package) file.
● Signing: The APK is signed with a digital certificate to verify its
authenticity.
● Installation: The signed APK is installed on the device for testing or
distribution.
7. Explain difference between view and view group?
● A View is a basic building block of UI in Android, representing a rectangular
area that can display content or respond to user interaction.
● A ViewGroup is a special type of View that can contain other Views
(including other ViewGroups) and define the layout structure of the UI.
8. List the Android App Components? Explain Activity Component?
● Android App Components include:
● Activity: Represents a single screen with a user interface.
● Service: Performs background tasks without a UI.
● BroadcastReceiver: Listens for system-wide broadcast announcements
or intents.
● ContentProvider: Manages a shared set of app data.
● Activity Component: An Activity is a core component of an Android app that
represents a single screen with a user interface. It manages the interaction
between the user and the app, handling events such as user input, screen
transitions, and lifecycle changes.
9. Define Intent? Explain different types of Intent?
● Intent is a messaging object used to request an action from another app
component. It facilitates communication between components such as
activities, services, and broadcast receivers.
● Different types of Intents include:

● Explicit Intent: Specifies the component to start by name (e.g.,


Activity, Service).
● Implicit Intent: Does not specify a component and instead describes the
type of action to perform, allowing the system to determine the best
component to handle the request.
● Broadcast Intent: Used to send system-wide messages or notifications
that can be received by any interested component.
● Pending Intent: Represents an Intent that will be executed in the future,
typically triggered by another app or system event.
10. Demonstrate with code snippet how to pass data between activities with Intent.
// Sending data from Activity1
Intent intent = new Intent(Activity1.this, Activity2.class);
intent.putExtra("key", "value");
startActivity(intent);

// Receiving data in Activity2


Intent intent = getIntent();
String data = intent.getStringExtra("key");

11. List features of the Android Operating System:


● Open Source: Android is built on open-source Linux kernel, allowing developers to
contribute and customize the OS.
● Multi-tasking: Android supports running multiple applications simultaneously,
allowing users to switch between them seamlessly.
● Customizable User Interface: Android provides widgets, themes, and launchers for
users to personalize their devices according to their preferences.
● Notifications: Android OS delivers notifications from apps and system events to
users, keeping them informed without constantly checking apps.
● Connectivity: Android supports various connectivity options such as Wi-Fi,
Bluetooth, NFC, and mobile data for seamless communication.
● Google Services Integration: Android integrates seamlessly with Google services like
Gmail, Maps, Drive, and Play Store.
● Security: Android offers multiple layers of security features, including app
sandboxing, encryption, and Google Play Protect.
● Google Assistant: Android devices come with Google Assistant, a virtual assistant
that helps users perform tasks, answer questions, and control smart devices.
● Multi-language Support: Android supports multiple languages and offers localization
features for global accessibility.
● Regular Updates: Android receives regular updates with new features, bug fixes, and
security patches to enhance user experience and security.
12. Define Android Virtual Devices (AVD):
● Android Virtual Devices (AVDs) are configurations of Android devices that run on
the Android Emulator. They allow developers to test their apps on different versions
of Android and various device configurations without needing physical devices.
AVDs emulate the hardware and software environment of real Android devices,
enabling developers to debug and test their apps in a simulated environment.
13. Write the directory path where images are stored while developing Android
applications:
● In Android development, images are typically stored in the res/drawable directory.
There are different drawable directories for different screen densities, such as
drawable-mdpi, drawable-hdpi, drawable-xhdpi, drawable-xxhdpi, and
drawable-xxxhdpi, where developers can place images optimized for different screen
resolutions.
14. List all attributes to develop a simple button:
● Attributes to develop a simple button in Android include:

● android:id: Unique identifier for the button.


● android:text: Text displayed on the button.
● android:layout_width and android:layout_height: Width and height of the
button.
● android:layout_margin: Margin around the button.

● android:padding: Padding inside the button.


● android:background: Background color or drawable for the button.
● android:textColor: Color of the text on the button.
● android:textSize: Size of the text on the button.
● android:onClick: Method to call when the button is clicked.
● android:enabled: Specifies if the button is enabled or disabled.
15. Write the syntax for Intent-Filter tag:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="http" />
<data android:scheme="https" />
</intent-filter>
16. Enlist the steps to publish the Android application:
1. Prepare your app by ensuring it's fully developed, tested, and optimized.
2. Create a developer account on the Google Play Console.
3. Prepare necessary assets like app icons, screenshots, and promotional
materials.
4. Build a signed release version of your app, either as an Android App Bundle
or an APK.
5. Complete the Store Listing details, including app title, description,
screenshots, and categorization.
6. Configure pricing and distribution options, including whether the app will be
free or paid and the countries where it will be available.
7. Upload your release to the Google Play Console and set up necessary release
tracks (e.g., internal testing, closed testing, production).
8. Perform necessary testing, including alpha and beta testing phases.
9. Roll out your app to production and monitor its performance, user feedback,
and reviews.
10. Regularly update your app with new features, bug fixes, and improvements
based on user feedback and performance metrics.
17. Differentiate between JVM and DVM:
1. JVM (Java Virtual Machine):
1. JVM is primarily used in traditional Java environments.
2. It executes Java bytecode and provides platform independence for Java
applications.
3. JVM runs on top of the host operating system and translates Java
bytecode into native machine code at runtime.
2. DVM (Dalvik Virtual Machine):
1. DVM was specifically designed for Android to optimize resource
usage in mobile environments.
2. It uses a register-based architecture instead of a stack-based one like
JVM.
3. DVM compiles each Java bytecode file into a Dalvik executable (.dex)
file, which is optimized for Android's memory and processing
constraints.
18. Discuss the need of permissions in Android. Describe the permissions to set
system functionalities of Internet:
1. Permissions in Android ensure that apps only have access to the resources and
data they legitimately need, enhancing security and privacy.
2. For system functionalities like Internet access, the INTERNET permission is
required. This permission allows the app to create network sockets and
send/receive data over the internet.
3. To set the INTERNET permission in an Android app, you need to include the
following line in the AndroidManifest.xml file:
<uses-permission android:name="android.permission.INTERNET" />

19. Demonstrate the usage of Implicit Intent with Code Snippet:


● Implicit intents are used to request functionality from other components in the
Android system without specifying the exact component to use.
● Example code snippet to open a webpage using an implicit intent:
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("https://www.example.com"));
startActivity(intent);

20. Demonstrate with a code snippet the usage of Switches:


● Switches are UI components used to toggle between two states, typically on/off or
true/false.
● Example XML code snippet to define a switch in a layout file
<Switch
android:id="@+id/switchExample"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Enable Feature"
android:checked="false" />
Example Java code snippet to handle switch state changes
Switch switchExample = findViewById(R.id.switchExample);
switchExample.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean
isChecked) {
// Handle switch state change
if (isChecked) {
// Switch is ON
} else {
// Switch is OFF
}
}
});

21. What is the WebView and Toast? Write the code to call in JAVA:
● WebView: WebView is a widget in Android that allows displaying web pages within
an Android application. It's essentially a browser embedded into the app.
// Example code to load a web page in a WebView
WebView webView = findViewById(R.id.webView);
webView.loadUrl("https://www.example.com");
Toast: Toast is a small message that pops up on the screen to display information to
the user for a short period of time.
// Example code to display a toast message
Toast.makeText(getApplicationContext(), "Hello, World!",
Toast.LENGTH_SHORT).show();

22. Describe the significance of SQLite database in Android:


● SQLite is a lightweight relational database management system that is embedded into
Android devices.
● SQLite database is significant in Android development as it provides a convenient and
efficient way to store, retrieve, and manage structured data within an Android
application.
● It offers features like transaction support, SQL query language support, and data
persistence, making it suitable for storing app data such as user preferences, settings,
cache, and structured content.
23. Explain the concept of Security in Android. Discuss about the Android Security
model:
● Security in Android involves protecting user data, preventing unauthorized access,
and ensuring the integrity of the device and its applications.
● Android security model includes multiple layers of protection such as:

● Application Sandbox: Each Android app runs in its own sandboxed


environment, ensuring that apps are isolated from each other and cannot
access data or resources of other apps without proper permissions.
● Permissions: Android apps require explicit user permissions to access
sensitive resources or perform certain actions, enhancing security and privacy.
● Code Signing: Android apps must be digitally signed with a certificate to
ensure their authenticity and integrity. This helps in preventing tampering and
unauthorized modifications.
● Android Security Enhancements: Android incorporates various security
features like Data Encryption, SELinux (Security-Enhanced Linux), Secure
Boot, and Google Play Protect to protect against malware, viruses, and other
security threats.
24. Write a program to change font size and colour of button in java:
Button button = findViewById(R.id.button);
// Change font size
button.setTextSize(20); // Set font size to 20sp
// Change text color
button.setTextColor(Color.BLUE); // Set text color to blue

25. Explain Multitouch. Write an Android program to implement the concept of


Multitouch:
● Multitouch refers to the ability of a touchscreen to detect and respond to multiple
touch points simultaneously, allowing users to perform multiple gestures or actions at
the same time.
● Example Android program to implement multitouch
@Override
public boolean onTouchEvent(MotionEvent event) {
int action = event.getActionMasked();
int pointerCount = event.getPointerCount();
switch (action) {
case MotionEvent.ACTION_DOWN:
case MotionEvent.ACTION_POINTER_DOWN:
// Handle touch down events
for (int i = 0; i < pointerCount; i++) {
int pointerId = event.getPointerId(i);
// Get touch coordinates
float x = event.getX(i);
float y = event.getY(i);
// Perform action based on touch
}
break;
case MotionEvent.ACTION_MOVE:
// Handle touch move events
for (int i = 0; i < pointerCount; i++) {
int pointerId = event.getPointerId(i);
// Get touch coordinates
float x = event.getX(i);
float y = event.getY(i);
// Perform action based on touch
}
break;
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_POINTER_UP:
// Handle touch up events
for (int i = 0; i < pointerCount; i++) {
int pointerId = event.getPointerId(i);
// Perform action based on touch
}
break;
}
return true;
}

PART C
2 Long Answer questions with answers per unit with answers (pattern - 2 questions of
10 marks each) Total 10 Questions.

1. Design an Android Architecture with all components:


Android architecture contains different number of components to support any android device
needs. Android software contains an open-source Linux Kernel having collection of number
of C/C++ libraries which are exposed through an application framework services.
Among all the components Linux Kernel provides main functionality of operating system
functions to smartphones and Dalvik Virtual Machine (DVM) provide platform for running
an android application.
The main components of android architecture are following:-
A. Applications
B. Application Framework
C. Android Runtime
D. Platform Libraries
E. Linux Kernel
Applications –
Applications is the top layer of android architecture. The pre-installed applications like home,
contacts, camera, gallery etc and third party applications downloaded from the play store like
chat applications, games etc. will be installed on this layer only.
It runs within the Android run time with the help of the classes and services provided by the
application framework.
Application framework –
Application Framework provides several important classes which are used to create an
Android application. It provides a generic abstraction for hardware access and also helps in
managing the user interface with application resources. Generally, it provides the services
with the help of which we can create a particular class and make that class helpful for the
Applications creation.
It includes different types of services activity manager, notification manager, view system,
package manager etc. which are helpful for the development of our application according to
the prerequisite.
Application runtime –
Android Runtime environment is one of the most important part of Android. It contains
components like core libraries and the Dalvik virtual machine(DVM). Mainly, it provides the
base for the application framework and powers our application with the help of the core
libraries.
Like Java Virtual Machine (JVM), Dalvik Virtual Machine (DVM) is a register-based
virtual machine and specially designed and optimized for android to ensure that a device can
run multiple instances efficiently. It depends on the layer Linux kernel for threading and low-
level memory management. The core libraries enable us to implement android applications
using the standard JAVA or Kotlin programming languages.
Platform libraries –
The Platform Libraries includes various C/C++ core libraries and Java based libraries such as
Media, Graphics, Surface Manager, OpenGL etc. to provide a support for android
development.

● Media library provides support to play and record an audio and video formats.
● Surface manager responsible for managing access to the display subsystem.
● SGL and OpenGL both cross-language, cross-platform application program
interface (API) are used for 2D and 3D computer graphics.
● SQLite provides database support and FreeType provides font support.

● Web-Kit This open source web browser engine provides all the functionality to
display web content and to simplify page loading.
● SSL (Secure Sockets Layer) is security technology to establish an encrypted link
between a web server and a web browser.
Linux Kernel –
Linux Kernel is heart of the android architecture. It manages all the available drivers such as
display drivers, camera drivers, Bluetooth drivers, audio drivers, memory drivers, etc. which
are required during the runtime.
The Linux Kernel will provide an abstraction layer between the device hardware and the
other components of android architecture. It is responsible for management of memory,
power, devices etc.
The features of Linux kernel are:

● Security: The Linux kernel handles the security between the application and the
system.
● Memory Management: It efficiently handles the memory management thereby
providing the freedom to develop our apps.
● Process Management: It manages the process well, allocates resources to
processes whenever they need them.
● Network Stack: It effectively handles the network communication.

● Driver Model: It ensures that the application works properly on the device and
hardware manufacturers responsible for building their drivers into the Linux build.

2. What is Activity Lifecycle in Android? Draw a suitable diagram of all


methods:
● The Activity Lifecycle in Android represents the various states an activity can
transition through during its lifetime. Here's a diagram illustrating the lifecycle
methods:
● onCreate(): Called when the activity is first created.
● onStart(): Called when the activity is becoming visible to the user.
● onResume(): Called when the activity will start interacting with the
user.
● onPause(): Called when the activity is partially obscured.

● onStop(): Called when the activity is no longer visible to the user.


● onDestroy(): Called before the activity is destroyed.

3. Design a Simple Calculator in Android with four buttons:


XML Layout (activity_main.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".CalculatorActivity">

<EditText
android:id="@+id/editTextNum1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:hint="Enter number 1"
android:inputType="numberDecimal"
android:layout_centerHorizontal="true"/>

<EditText
android:id="@+id/editTextNum2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editTextNum1"
android:layout_marginTop="16dp"
android:hint="Enter number 2"
android:inputType="numberDecimal"
android:layout_centerHorizontal="true"/>

<Button
android:id="@+id/buttonAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editTextNum2"
android:layout_marginTop="16dp"
android:text="+"
android:onClick="onAddButtonClick"
android:layout_alignStart="@id/editTextNum1"/>

<Button
android:id="@+id/buttonSubtract"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editTextNum2"
android:layout_marginTop="16dp"
android:text="-"
android:onClick="onSubtractButtonClick"
android:layout_toEndOf="@id/buttonAdd"/>

<Button
android:id="@+id/buttonMultiply"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonAdd"
android:layout_marginTop="16dp"
android:text="*"
android:onClick="onMultiplyButtonClick"
android:layout_alignStart="@id/editTextNum1"/>

<Button
android:id="@+id/buttonDivide"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonAdd"
android:layout_marginTop="16dp"
android:text="/"
android:onClick="onDivideButtonClick"
android:layout_toEndOf="@id/buttonMultiply"/>

<EditText
android:id="@+id/editTextResult"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonMultiply"
android:layout_marginTop="16dp"
android:hint="Result"
android:inputType="numberDecimal"
android:enabled="false"
android:layout_centerHorizontal="true"/>

</RelativeLayout>

Java Code (CalculatorActivity.java)

public class CalculatorActivity extends AppCompatActivity {

private EditText editTextNum1;


private EditText editTextNum2;
private EditText editTextResult;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_calculator);

editTextNum1 = findViewById(R.id.editTextNum1);
editTextNum2 = findViewById(R.id.editTextNum2);
editTextResult = findViewById(R.id.editTextResult);
}

public void onAddButtonClick(View view) {


double num1 = Double.parseDouble(editTextNum1.getText().toString());
double num2 = Double.parseDouble(editTextNum2.getText().toString());
double result = num1 + num2;
editTextResult.setText(String.valueOf(result));
}

public void onSubtractButtonClick(View view) {


double num1 = Double.parseDouble(editTextNum1.getText().toString());
double num2 = Double.parseDouble(editTextNum2.getText().toString());
double result = num1 - num2;
editTextResult.setText(String.valueOf(result));
}

public void onMultiplyButtonClick(View view) {


double num1 = Double.parseDouble(editTextNum1.getText().toString());
double num2 = Double.parseDouble(editTextNum2.getText().toString());
double result = num1 * num2;
editTextResult.setText(String.valueOf(result));
}

public void onDivideButtonClick(View view) {


double num1 = Double.parseDouble(editTextNum1.getText().toString());
double num2 = Double.parseDouble(editTextNum2.getText().toString());
if (num2 != 0) {
double result = num1 / num2;
editTextResult.setText(String.valueOf(result));
} else {
editTextResult.setText("Cannot divide by zero");
}
}
}

4. Explain and five Platform Libraries of Android Architecture.


a. android.database: This package provides classes to manage databases
using SQLite in Android applications. SQLite is a lightweight
relational database management system embedded in Android.
b. android.opengl: This package contains the classes to support OpenGL
(Open Graphics Library) ES (Embedded Systems) in Android
applications. OpenGL ES is a subset of the OpenGL specification
adapted for embedded systems such as mobile devices.
c. android.graphics: This package provides classes for 2D and 3D
graphics rendering, including drawing shapes, text, and images on the
screen. It includes classes for canvas drawing, bitmap manipulation,
color management, and more.
d. android.print: This package contains classes and interfaces for
printing support in Android applications. It allows developers to add
printing capabilities to their apps, enabling users to print documents,
images, and other content directly from their devices.
e. android.media: As previously mentioned, this library offers classes
and interfaces for handling multimedia content in Android
applications. It includes features for audio and video playback,
recording, streaming, and media file management. Developers leverage
this library to create multimedia players, voice recording apps, video
streaming services, and other media-related applications.

5. WAP in android to Check login credentials, if correct print successfully if


not then print try again in toast.
Ans : MainActivity.java

import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

private EditText usernameEditText, passwordEditText;


private Button loginButton;

// Dummy login credentials


private static final String CORRECT_USERNAME = "user";
private static final String CORRECT_PASSWORD = "password";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

// Initialize views
usernameEditText = findViewById(R.id.usernameEditText);
passwordEditText = findViewById(R.id.passwordEditText);
loginButton = findViewById(R.id.loginButton);

// Set click listener for login button


loginButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Get input from EditText fields
String username = usernameEditText.getText().toString();
String password = passwordEditText.getText().toString();

// Check if login credentials are correct


if (username.equals(CORRECT_USERNAME) &&
password.equals(CORRECT_PASSWORD)) {
// Display success message
showToast("Login successful");
} else {
// Display error message
showToast("Try again");
}
}
});
}

// Method to display toast message


private void showToast(String message) {
Toast.makeText(MainActivity.this, message, Toast.LENGTH_SHORT).show();
}
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

<EditText
android:id="@+id/usernameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:layout_marginTop="100dp"
android:padding="10dp"/>

<EditText
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:layout_below="@id/usernameEditText"
android:layout_marginTop="20dp"
android:padding="10dp"/>

<Button
android:id="@+id/loginButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_below="@id/passwordEditText"
android:layout_marginTop="20dp"
android:layout_centerHorizontal="true"
android:padding="10dp"/>

</RelativeLayout>

6. Explain the components of AndroidManifest.xml file and build. Gradle file


AndroidManifest.xml File:

The AndroidManifest.xml file is a crucial component of an Android application. It provides


essential information about the app to the Android system, such as its package name, version,
permissions required, activities, services, broadcast receivers, content providers, and more.
Here are the key components of the AndroidManifest.xml file:

1. <manifest>: The root element of the manifest file that contains essential information
about the app, such as its package name and version code.
2. <application>: Encloses all the components of the application, including activities,
services, broadcast receivers, and content providers. It also defines application-wide
properties and permissions.
3. <activity>: Declares an activity in the application. Each activity represents a screen
with a user interface.
4. <service>: Declares a background service that performs long-running operations
without a user interface.
5. <receiver>: Declares a broadcast receiver component that responds to system-wide
broadcast announcements.
6. <provider>: Declares a content provider component that manages a shared set of app
data.
7. <intent-filter>: Specifies the types of intents that the component can respond to. It
defines the actions, categories, and data types supported by the component.
8. <uses-permission>: Declares permissions required by the application to access
certain system features or perform specific actions.
build.gradle File:
The build.gradle file is a configuration file used by the Gradle build system to customize the
build process of an Android project. It defines build settings, dependencies, and other
configurations specific to the project. Here are the key components of the build.gradle file:

1. buildscript: Defines the dependencies and repositories required for the build script
itself.
2. dependencies: Specifies the dependencies required by the project, such as libraries,
plugins, and other external modules.
3. android: Configures settings for the Android build, such as compile SDK version,
build types (debug, release), product flavors, and build variants.
4. defaultConfig: Specifies default configurations for the app, such as application ID,
version code, version name, minimum SDK version, and target SDK version.
5. repositories: Specifies the repositories where Gradle should look for dependencies,
such as Maven Central, Google Maven, or local repositories.
6. task: Defines custom tasks or modifies existing tasks in the build process.

7. What are an android alert Dialogs? Explain with suitable code

Android AlertDialog can be used to display the dialog message with OK and Cancel
buttons. It can be used to interrupt and ask the user about his/her choice to continue or
discontinue.
Android AlertDialog is composed of three regions: title, content area and action
buttons.
Android AlertDialog is the subclass of Dialog class.
Methods of AlertDialog class
Method Description

public AlertDialog.Builder setTitle(CharSequence) This method is used to set the title of AlertDialog.

public AlertDialog.Builder setMessage(CharSequence) This method is used to set the message for AlertDialog.

public AlertDialog.Builder setIcon(int) This method is used to set the icon over AlertDialog.
XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.javatpoint.com.alertdialog.MainActivity">

<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:text="Close app"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />

</android.support.constraint.ConstraintLayout>

JAVA

package example.javatpoint.com.alertdialog;
import android.content.DialogInterface;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.app.AlertDialog;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


Button closeButton;
AlertDialog.Builder builder;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

closeButton = (Button) findViewById(R.id.button);


builder = new AlertDialog.Builder(this);
closeButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {

//Uncomment the below code to Set the message and title from the
strings.xml file
builder.setMessage(R.string.dialog_message) .setTitle(R.string.dialog_title)
;

//Setting message manually and performing action on button click


builder.setMessage("Do you want to close this application ?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
Toast.makeText(getApplicationContext(),"you choose yes action
for alertbox",
Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
// Action for 'NO' Button
dialog.cancel();
Toast.makeText(getApplicationContext(),"you choose no action
for alertbox",
Toast.LENGTH_SHORT).show();
}
});
//Creating dialog box
AlertDialog alert = builder.create();
//Setting the title manually
alert.setTitle("AlertDialogExample");
alert.show();
}
});
}
}
8. What are an android alert Dialogs? Explain with suitable code

a. Check Box
b. ImageButton
c. ImageView
d. RadioButton
e. Button

a. Check Box:

<CheckBox
android:id="@+id/checkBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Check Box" />

b. ImageButton:

<ImageButton
android:id="@+id/imageButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image" />

c. ImageView:

<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/image" />

d. RadioButton:

<RadioButton
android:id="@+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Radio Button" />

e. Button:

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button" />
9. How to use Google Maps API to implement location based services in an
application?

Google Maps API provides developers with powerful tools to integrate mapping and
location-based services into their Android applications. Here's a brief overview of how to use
Google Maps API for location-based services:

1. Obtain API Key: First, you need to obtain an API key from the Google Cloud
Platform Console. This key is required to access Google Maps API services.
2. Add Google Play Services Dependency: In your app's build.gradle file, include the
Google Play Services dependency to access Google Maps API features.
3. Add Map Fragment to Layout: In your XML layout file, add a
SupportMapFragment or MapView to display the map.
4. Initialize Google Maps: In your activity's onCreate() method, initialize Google
Maps by obtaining a reference to the GoogleMap object.
5. Set Up Map Configuration: Configure the map settings such as zoom controls, map
type, and other UI settings.
6. Access User's Location: To access the user's current location, you can use the
LocationManager or FusedLocationProviderClient to request location updates.
Ensure you have the necessary location permissions declared in the manifest file.
7. Add Markers and Overlays: You can add markers, polylines, polygons, and other
overlays to the map to provide additional information.
8. Handle Map Events: Implement event listeners to handle user interactions with the
map, such as clicks on markers or map gestures.
9. Customize Map Styling: Optionally, you can customize the map's appearance using
the Maps Styling feature to match your app's design.
10. Testing and Debugging: Test your application on real devices and emulators to
ensure proper functionality. Use debugging tools to troubleshoot any issues.
11. Deploy: Once your application is ready, deploy it to the Google Play Store or
distribute it through other channels.

10. How does the Wi-Fi technology work in Android explain using WifiManager ?

Wi-Fi technology in Android is managed through the WifiManager class, which provides
methods to enable/disable Wi-Fi, scan for available networks, connect to networks, and
obtain information about the device's Wi-Fi connection. Here's how Wi-Fi technology works
in Android using WifiManager:

1. Initialize WifiManager: Obtain an instance of the WifiManager using the


getSystemService() method.
2. Enable/Disable Wi-Fi: Use the setWifiEnabled(true/false) method to enable or
disable Wi-Fi on the device programmatically.
3. Scan for Available Networks: Use the startScan() method to initiate a scan for
available Wi-Fi networks. Register a BroadcastReceiver to receive the scan results.
4. Retrieve Scan Results: Once the scan is complete, use the getScanResults() method
to obtain a list of available Wi-Fi networks. Each scan result contains information
such as SSID, BSSID, signal strength, etc.
5. Connect to a Network: Use the WifiConfiguration class to create a configuration
for the desired network and then use addNetwork() and enableNetwork() methods to
connect to the network.
6. Monitor Wi-Fi State Changes: Register a BroadcastReceiver to monitor Wi-Fi state
changes and receive notifications when the device connects or disconnects from a Wi-
Fi network.
7. Retrieve Connection Information: Use methods like getConnectionInfo() to obtain
information about the current Wi-Fi connection, such as SSID, BSSID, IP address,
etc.
8. Handle Wi-Fi Events: Implement event listeners to handle Wi-Fi-related events such
as network state changes, connection failures, etc.
9. Permissions: Ensure that your app has the necessary permissions declared in the
manifest file, such as ACCESS_WIFI_STATE, CHANGE_WIFI_STATE,
ACCESS_FINE_LOCATION, etc., depending on the functionality required.

By leveraging the WifiManager class and related APIs, developers can create Android
applications that interact with Wi-Fi networks effectively, providing users with enhanced
connectivity features and capabilities.

You might also like