You are on page 1of 11

Q.1. What is Android? List out the different features of Android.

Android is an open-source mobile operating system primarily designed for smartphones and
tablets. Developed by Google, it provides a flexible and customizable platform for device
manufacturers and developers to create a wide range of applications and services. Android offers
various features that contribute to its popularity and functionality. Here are some key features of
Android:
 User Interface: Android offers a user-friendly interface with customizable home screens,
widgets, and app icons. Users can personalize their devices according to their preferences.
 Multitasking: Android supports multitasking, allowing users to run multiple applications
simultaneously. They can switch between apps, use split-screen mode, and perform tasks
efficiently.
 Notifications: Android provides a rich notification system that keeps users informed about
messages, emails, updates, and other activities. Notifications appear on the lock screen and can
be expanded or interacted with.
 Google Play Store: Android devices have access to the Google Play Store, a vast marketplace
offering a wide range of apps, games, books, movies, and more. Users can download and install
applications easily.
 Connectivity: Android supports various connectivity options, including Wi-Fi, Bluetooth, NFC,
and cellular data. It enables users to connect and share data with other devices, accessories,
and networks.
Q.2. Explain Android architecture in brief.
The Android operating system architecture is based on a layered approach, with each layer performing specific
functions and interacting with the layers above and below it. Here is a comprehensive breakdown of the Android
architecture:

1. Linux Kernel: At the foundation of the Android architecture lies the Linux kernel, which serves
as an abstraction layer between the hardware and the software layers above it. The Linux
kernel provides essential services such as device drivers, memory management, process
management, networking, and security.
2. Hardware Abstraction Layer (HAL): The Hardware Abstraction Layer sits above the Linux
kernel and provides a standardized interface for the Android framework to interact with
various hardware components. It acts as a bridge between the device-specific drivers and the
rest of the software stack. By abstracting hardware-specific details, the HAL allows the
Android framework to be device-agnostic, making it easier for manufacturers to create
Android devices with different hardware configurations.
3. Native Libraries: The Native Libraries consist of a collection of pre-compiled libraries written in
C and C++. These libraries provide core functionalities to the Android system and applications.
They cover areas such as graphics rendering, media playback, database management, SSL
encryption, and more. Examples of these libraries include the Surface Manager, Media
Framework, SQLite database engine, and WebKit for web rendering.
4. Android Runtime (ART): The Android Runtime, introduced in later versions of Android, is
responsible for executing Android applications. It consists of the following components:
a. Ahead-of-Time (AOT) Compiler: During the application installation process, the bytecode
of the app's executable files (DEX files) is converted into native machine code using the
AOT compiler. This compilation step improves the performance of the application by
reducing the need for just-in-time (JIT) compilation during runtime.
b. Core Libraries: The Android runtime includes a set of core libraries that provide common
functionality to Android applications. These libraries, written in Java, allow developers to
access features such as data structures, math functions, file I/O, networking, and more.
c. ART Virtual Machine: The ART Virtual Machine is responsible for running the compiled
native code of Android applications. It manages the execution of applications, garbage
collection, memory management, and thread management.
5. Android Framework: The Android Framework is a collection of reusable software components
and tools that developers use to build applications. It provides a rich set of APIs and services
to simplify the development process. The key components of the Android Framework include:
a. Activity Manager: Manages the lifecycle of applications and provides a framework for
creating user interfaces through activities.
b. Content Providers: Enable applications to securely share data with other applications by
providing a standardized interface to access and manage data.
c. Resource Manager: Handles access to non-code resources such as images, strings,
layouts, and colors.
d. Notification Manager: Manages the generation and display of notifications to keep users
informed about events and activities.
e. Telephony Manager: Provides access to telephony-related functionalities such as making
calls, sending SMS messages, and monitoring phone state.
f. Location Manager: Allows applications to retrieve information about the device's location
using various location providers such as GPS, Wi-Fi, or cellular networks.
g. View System: Provides a set of UI components and layout managers for creating user
interfaces.
h. Package Manager: Manages the installation, updating, and removal of applications on the
device.
6. Application Layer: The topmost layer of the Android architecture is the Application Layer,
where users interact with applications installed on their devices. This layer consists of system
applications pre-installed by the device manufacturer (e.g., Phone, Contacts, Messaging) and
third-party applications installed by the user from sources such as the Google Play Store or
other app stores. Applications in this layer can utilize the functionalities provided by the
Android Framework and interact with system services through well-defined APIs.
Q.3. Elaborate the structure of Android Manifest file
The Android Manifest file is a crucial component of an Android application. It serves as a metadata
file that provides essential information about the application to the Android system. The structure
of the Android Manifest file can be divided into several sections:
 XML Declaration: The Manifest file begins with an XML declaration, specifying the XML version
and encoding.
 Manifest Element: The root element of the Manifest file is the <manifest> element, which
encapsulates all other elements. It contains attributes that define essential properties of the
application, including package name, version information, and platform compatibility
requirements.
 <uses-permission> Element: This element is used to declare permissions that the application
requires to access specific system resources or perform certain actions. It lists the permissions
needed by the application, such as accessing the internet, using the camera, reading or writing
to external storage, and more.
 <uses-sdk> Element: The <uses-sdk> element specifies the minimum and target API levels
required by the application. It includes attributes such as minSdkVersion and targetSdkVersion,
which define the minimum and preferred versions of the Android SDK that the application
supports.
 <application> Element: The <application> element contains information and settings related to
the application itself. It includes attributes such as android:label for specifying the application's
display name and android:icon for setting the application icon. It also encapsulates other
components and declarations within the application.
 <activity> Element: The <activity> element represents an activity within the application, which
represents a single screen with a user interface. It includes attributes like android:name for
specifying the activity class name, android:label for setting the activity's display name, and
android:theme for defining the visual theme of the activity.
 <service>, <receiver>, and <provider> Elements: These elements are used to declare services,
broadcast receivers, and content providers, respectively. Services perform background tasks,
broadcast receivers handle system-wide events, and content providers enable sharing data
between applications.
 <intent-filter> Element: The <intent-filter> element is used within activity, service, and receiver
declarations to specify the types of intents they can handle. It contains child elements like
<action>, <category>, and <data> to define the actions, categories, and data types the
component can respond to.
 Other Elements: The Manifest file may also include other elements such as <meta-data> to
provide additional metadata about the application, <uses-library> to declare dependencies on
shared libraries, and <uses-feature> to specify features required by the application.
The Android Manifest file serves as a blueprint for the Android system to understand the structure,
capabilities, and requirements of an application. It plays a crucial role in the installation, launch,
and interaction of the application with the operating system and other applications.
Q.4. Explain the core building blocks of Android?
The core building blocks of Android are fundamental components that developers use to build
applications. These building blocks represent different aspects of an application's functionality and
define its behavior and interaction with the user. The core building blocks of Android are as
follows:
1. Activities: Activities represent the user interface (UI) and screen of an application. They serve
as the entry point for user interaction and typically represent a single focused task. Each
activity is defined by a Java class and an associated XML layout file that defines the UI
elements. Activities can be organized into a stack, allowing users to navigate back and forth
between different screens.
2. Services: Services are components that run in the background and perform long-running
operations or handle tasks that do not require a UI. They can continue to run even if the user
switches to another application. Services are commonly used for tasks such as playing music,
downloading files, or processing data in the background.
3. Broadcast Receivers: Broadcast Receivers listen for system-wide broadcast messages or intents
and respond to them. They enable communication between the Android system, applications,
and external sources. Broadcast Receivers can perform actions in response to system events,
such as receiving a new SMS message or when the device boots up.
4. Content Providers: Content Providers enable applications to share data with other applications
securely. They provide a standardized interface for data access, allowing applications to query,
insert, update, and delete data. Content Providers can manage data stored in a database, file,
or any other data source and ensure data integrity and access control.
5. Intents: Intents are messages that enable communication between components within an
application or between different applications. They facilitate various operations, such as
starting activities, launching services, sending broadcasts, and establishing inter-process
communication. Intents carry information in the form of key-value pairs called extras and can
also specify the desired action to be performed.
6. Fragments: Fragments are reusable UI components that can be combined within an activity to
create a flexible and modular user interface. They represent a portion of a UI or a behavior that
can be added or removed from an activity dynamically. Fragments are often used to build
responsive and multi-pane layouts that adapt to different screen sizes and orientations.
These core building blocks work together to create dynamic and interactive applications on the
Android platform. By utilizing these components effectively, developers can build versatile and
user-friendly applications that provide seamless experiences to Android users.
Q.5. Define Activity. Explain android activity lifecycle.
An Activity in Android represents a single screen or user interface (UI) component within an
application. It is a fundamental building block that allows users to interact with the application's UI
and perform various actions. Each activity is defined by a Java class that extends the
android.app.Activity class and typically has an associated XML layout file that defines the visual
elements of the UI.
The Android activity lifecycle describes the various states and transitions an activity goes
through during its lifetime. Understanding the activity lifecycle is crucial for managing the UI state,
handling user interactions, and ensuring proper resource management. The Android activity
lifecycle consists of the following states and callbacks:
1. Created (onCreate()): The activity is created when it is first launched or when it is brought back
to the foreground after being in a stopped or destroyed state. The onCreate() method is called
during this state, where initialization tasks such as UI setup, binding data, and initializing
variables should be performed.
2. Started (onStart()): After the onCreate() method is executed, the activity enters the started
state. The onStart() method is called, indicating that the activity is now visible to the user but
may not have the focus. In this state, the activity is in the foreground but not yet interactable.
3. Resumed (onResume()): When the activity comes into the foreground and gains user focus, it
enters the resumed state. The onResume() method is called, and the activity is now active and
ready for user interaction. This is the state where the activity is in the foreground and is
actively interacting with the user.
4. Paused (onPause()): The activity enters the paused state when it loses focus but remains visible
to the user. This can happen when another activity is launched on top of the current activity or
when the device's screen is partially obscured. The onPause() method is called during this state,
allowing the activity to save any transient data and release resources that are not needed while
the activity is not in the foreground.
5. Stopped (onStop()): If the activity is no longer visible to the user or has been explicitly stopped,
it enters the stopped state. The onStop() method is called, indicating that the activity is no
longer in the foreground. In this state, the activity is still alive in memory, but it is not visible
and cannot interact with the user.
6. Destroyed (onDestroy()): The activity enters the destroyed state when it is finished or explicitly
destroyed by calling the finish() method. The onDestroy() method is called, allowing the activity
to perform any final cleanup and release any resources it holds. Once an activity is destroyed, it
is removed from memory and can no longer be accessed.
Q.6. What is mean by Android Service? Explain its lifecycle.
In Android, a Service is a component that runs in the background, independently of any user
interface (UI). It performs long-running operations or handles tasks that don't require direct user
interaction. Services are often used for tasks such as playing music, fetching data from a server, or
performing background computations.
The Android Service lifecycle describes the different states and transitions that a service goes
through during its lifetime. Understanding the service lifecycle is essential for managing resources,
controlling the service's behavior, and ensuring proper operation. The Android service lifecycle
consists of the following states and callbacks:
1. Created (onCreate()): When a service is first created, the onCreate() method is called. This is
where initialization tasks, such as setting up resources or establishing connections, should be
performed. Once the onCreate() method completes, the service moves to the next state.
2. Started (onStartCommand()): After the onCreate() method is executed, the service enters the
started state. The onStartCommand() method is called, indicating that the service is now
running and ready to handle requests. This is where you can define the logic for processing
incoming commands or intents.
3. Running: When a service is in the running state, it continues to execute its logic or perform its
designated tasks until it is explicitly stopped or encounters an error. The service remains in this
state until it is either stopped by calling the stopService() method or until the system destroys it
to reclaim resources.
4. Destroyed (onDestroy()): When a service is stopped or no longer needed, the onDestroy()
method is called. This allows the service to clean up any resources it acquired during its
lifetime. Once the onDestroy() method completes, the service is considered destroyed and can
no longer be started or interacted with.
Q.8. List out Android Layouts and explain them in brief.
Android provides a variety of layout options to define the UI of an application. These layouts help
organize and position UI elements within an activity or fragment. Here are some of the commonly
used Android layouts:
 LinearLayout: LinearLayout arranges UI elements in a linear fashion, either horizontally or
vertically. It uses the android:orientation attribute to specify the orientation. Elements are
arranged one after another in the specified direction.
 RelativeLayout: RelativeLayout allows positioning UI elements relative to each other or relative
to the parent container. It uses attributes like android:layout_alignParentTop,
android:layout_alignParentBottom, android:layout_above, android:layout_below, etc., to
define the relative positioning of elements.
 ConstraintLayout: ConstraintLayout is a flexible layout that allows creating complex UI designs
with a flat view hierarchy. It uses constraints to define the position and relationships between
UI elements. It offers features like flexible dimensions, aspect ratio, and chains to create
adaptive and responsive layouts.
 FrameLayout: FrameLayout is a simple layout that acts as a placeholder for a single UI element
or view. It is commonly used to display a single view on the screen, such as an image, text, or a
fragment. Views added to a FrameLayout are stacked on top of each other.
 TableLayout: TableLayout arranges UI elements in a grid-like structure with rows and columns.
It uses <TableRow> elements to define rows and adds views within the rows. TableLayout is
useful when you need to display data in a tabular format.
 GridLayout: GridLayout is a grid-based layout that allows arranging UI elements in rows and
columns. It provides more control over the positioning and sizing of elements compared to
TableLayout. GridLayout supports both fixed and variable cell sizes.
 CoordinatorLayout: CoordinatorLayout is a powerful layout that provides control over the
positioning and behavior of its child views. It's designed to work with the Material Design
concept of motion and interaction. CoordinatorLayout can coordinate the scrolling and
animation effects of its child views.
 ScrollView: ScrollView is a container that allows its contents to scroll vertically or horizontally.
It's used when the content of a layout exceeds the available space on the screen. ScrollView
can hold only one child view or layout.
 CardView: CardView is a container that provides a material design card-like appearance. It can
be used to display various types of content, such as images, text, or other UI elements.
CardView is often used in lists or for displaying individual items.
These are just a few of the many layouts available in Android. Each layout offers different
capabilities and can be used based on the specific requirements of your application's UI design.
Q.7. Write a short note on –
1. Android Runtime:
The Android Runtime (ART) is the runtime environment used by the Android operating
system to execute applications written in the Java programming language. ART is a key component
of the Android platform and plays a crucial role in the performance and execution of Android
applications.
The Android Runtime (ART) is the runtime environment used by Android to execute Java-
based applications. It evolved from the earlier Dalvik Virtual Machine and introduced Ahead-of-
Time (AOT) compilation, improving app startup times and performance. ART also features a more
efficient garbage collector, reduced memory footprint, support for native development, and
maintains compatibility with Java. Overall, ART enhances the execution and efficiency of Android
applications.
2. DVM
The Dalvik Virtual Machine (DVM) was the virtual machine used by the Android operating system
prior to the introduction of the Android Runtime (ART). It was specifically designed for running
Android applications and executing bytecode written in the Java programming language.
Key features of the Dalvik Virtual Machine include:
 Register-based Architecture: The DVM used a register-based architecture rather than the stack-
based architecture of the traditional Java Virtual Machine (JVM). This allowed for more
efficient execution of bytecode and reduced memory usage.
 Just-in-Time (JIT) Compilation: The DVM utilized a Just-in-Time (JIT) compilation approach.
During runtime, the DVM would dynamically translate parts of the application's bytecode into
native machine code, optimizing performance for frequently executed code paths.
 Optimal Memory Management: The DVM implemented a sophisticated garbage collector that
efficiently managed memory by automatically reclaiming memory occupied by unused objects,
thereby reducing memory fragmentation.
 Application Sandbox: The DVM enforced the application sandboxing model, ensuring that each
Android application runs in its isolated environment with restricted access to system resources.
This provided enhanced security and prevented malicious apps from interfering with other
applications or the underlying operating system.
3. Android SDK & its components
The Android Software Development Kit (SDK) is a collection of tools, libraries, and resources
provided by Google for developing Android applications. It includes everything needed to build,
test, and debug Android apps. The key components of the Android SDK are as follows:
 SDK Tools: The SDK Tools consist of various command-line utilities and helper programs
required for Android development, such as the Android Debug Bridge (ADB) for device
communication, the Android Emulator for testing, and the Android Asset Packaging Tool (AAPT)
for resource management.
 SDK Platform-Tools: The Platform-Tools include essential tools for developing on Android
devices, including ADB, Fastboot, and other debugging and profiling tools.
 SDK Build Tools: The Build Tools are responsible for compiling, packaging, and signing Android
app projects. They include the Android Asset Packaging Tool (AAPT2), the Android Debugging
Bridge (ADB), and other utilities.
 Android API Levels: The Android SDK provides a set of API levels, which represent different
versions of the Android platform. Developers can target specific API levels to ensure
compatibility with different devices and access the latest features and enhancements.
 Support Libraries: The Support Libraries provide additional features and compatibility across
different Android versions. They include libraries for UI design, backward compatibility,
appcompat, RecyclerView, and more.
5. Android Services & their types
Android Services & their types: Android Services are components that run in the background and
perform tasks or operations that don't require direct user interaction. They can continue to run
even if the user switches to another application. Android Services are categorized into different
types:
 Started Services: Started services are initiated by calling the startService() method. They
perform a specific task and may continue to run even if the initiating component (such as an
activity) is destroyed. Started services need to be explicitly stopped using the stopService() or
stopSelf() method.
 Bound Services: Bound services allow components (such as activities) to bind to them and
interact with them through an interface. Bound services are used for inter-process
communication and can be used to perform tasks on behalf of other components. They are
bound using the bindService() method and unbound using the unbindService() method.
 Foreground Services: Foreground services are a special type of service that have a higher
priority and visibility. They provide ongoing user notifications to indicate their operation and
are used for tasks that require continuous user attention, such as playing music or tracking
location.
 Intent Services: Intent services are a subclass of the Service class that simplify the
implementation of background tasks. They handle each intent sent to them sequentially on a
worker thread, allowing for asynchronous execution of tasks without explicitly managing
threads.
UNIT III
Q.24. Explain in brief Broadcast and Broadcast Receivers in Android.
In Android, a broadcast is a system-wide message that can be sent by the system or by
applications to notify other components about events or actions that have occurred. It allows
different parts of an application or different applications to communicate with each other
indirectly.
A broadcast can be considered as a publish-subscribe mechanism, where senders (broadcasters)
publish messages, and receivers (broadcast receivers) subscribe to receive those messages. The
sender broadcasts an intent, which contains information about the event, and the system or
interested components receive and handle that intent.
Broadcast Receivers, also known as broadcast listeners, are components that receive and respond
to broadcast messages. They can be registered either statically in the AndroidManifest.xml file or
dynamically at runtime. When a matching broadcast intent is sent, the system identifies and
delivers the intent to the appropriate receivers.
Key points about Broadcast and Broadcast Receivers in Android:
 Broadcasting: Broadcasting refers to the process of sending a broadcast message to the system
or other interested components. It allows developers to notify other components about
events, system changes, or custom actions.
 Intent Filters: Broadcast receivers are registered with intent filters, which specify the type of
broadcast they are interested in. An intent filter defines the criteria for matching the broadcast
intent, such as action, category, or data. Multiple receivers can be registered to receive the
same broadcast if their intent filters match.
 System Broadcasts: Android provides a set of predefined system broadcasts, such as the device
boot completed, network connectivity changes, battery low, etc. Developers can also create
custom broadcasts specific to their application's needs.
 Ordered Broadcasts: Broadcasts can be either ordered or unordered. In an ordered broadcast,
receivers have the option to prioritize the handling of the intent. They can modify the intent or
abort the broadcast. Ordered broadcasts allow for cascading or chaining of receivers, where
one receiver can pass the intent to the next receiver in line.
 Sticky Broadcasts: Sticky broadcasts are special broadcasts that remain active even after they
are sent. When a receiver registers for a sticky broadcast, it immediately receives the last
broadcast of that type. Sticky broadcasts can be useful for components that need to know the
most recent information upon registration.
Q.25. How to implement Broadcast receiver in Android.

Q.27. What are intents in Android? Explain its types with example.
In Android, an Intent is a messaging object used to communicate between components within an
application or between different applications. It serves as a fundamental building block for various
operations, such as starting activities, launching services, and sending broadcast messages.
Intents are used to convey two types of information: the action to be performed and the data
associated with that action.
There are two main types of Intents in Android:
1. Explicit Intents: An explicit intent is used when you want to start a specific component within
your own application, such as starting a new activity or a service. It explicitly specifies the
target component's class name or component name.
Example of Explicit Intent:
Intent intent = new Intent(MainActivity.this, SecondActivity.class); startActivity(intent);
In the above example, an explicit intent is used to start the SecondActivity from MainActivity.
2. Implicit Intents: An implicit intent is used when you want to perform an action that can be
handled by any component on the device, without specifying the exact target component. The
system resolves the intent and prompts the user to select the appropriate application to handle
the requested action.
Example of Implicit Intent:
Intent intent = new Intent(Intent.ACTION_SEND); intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, "Hello, this is a sharing example!");
startActivity(Intent.createChooser(intent, "Share via"));
In the above example, an implicit intent is used to share some text content. The ACTION_SEND
Q.27.List out different system broadcasts. Give example by implementing any one of them.
Here are some commonly used system broadcasts in Android:
 ACTION_BOOT_COMPLETED: Broadcast sent when the device completes the boot process.
 ACTION_SCREEN_ON: Broadcast sent when the screen is turned on.
 ACTION_SCREEN_OFF: Broadcast sent when the screen is turned off.
 ACTION_POWER_CONNECTED: Broadcast sent when the device is connected to a power
source.
 ACTION_POWER_DISCONNECTED: Broadcast sent when the device is disconnected from a
power source.
 ACTION_BATTERY_LOW: Broadcast sent when the device's battery level becomes low.
 ACTION_BATTERY_OKAY: Broadcast sent when the device's battery level returns to normal
after being low.
 ACTION_HEADSET_PLUG: Broadcast sent when a headset is plugged into the device's audio
jack.
 ACTION_WIFI_STATE_CHANGED: Broadcast sent when the device's Wi-Fi state changes.
 ACTION_AIRPLANE_MODE_CHANGED: Broadcast sent when the device's airplane mode is
turned on or off.
These are just a few examples of system broadcasts available in Android.
Example implementation: To receive the ACTION_BOOT_COMPLETED broadcast, you need to
register a broadcast receiver in your AndroidManifest.xml file with the corresponding intent filter.
.xml fie
<receiver android:name=".BootCompletedReceiver"> <intent-filter> <action
android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>
Create a BroadcastReceiver class BootCompletedReceiver and override the onReceive() method to
handle the broadcast.
.javafile
public class BootCompletedReceiver extends BroadcastReceiver { @Override public void
onReceive(Context context, Intent intent) { if
(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)) { // Perform actions on boot
completed // For example, start a service or schedule a job } } }
Xml file
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

Q.26. Write a short note on –


1. Intent Filters in Android
In Android, Intent Filters are used to declare the types of intents that a component can
receive or respond to. They define the criteria that determine whether a component can handle a
specific type of intent. Intent Filters are typically declared in the manifest file
(AndroidManifest.xml) of an application.
Intent Filters consist of one or more elements, such as action, category, and data, which
collectively define the characteristics of the intent. These elements are used to match the
incoming intent with the declared filters of various components in the system, allowing the system
to identify the appropriate component to handle the intent.
Intent Filters provide a powerful mechanism in Android to declare the capabilities and
intent handling abilities of components. By properly defining intent filters, you can ensure that
your components are invoked correctly when appropriate intents are sent, enabling effective
inter-component communication and seamless integration with other parts of the system.
2.system broadcasts:
System broadcasts, also known as system-wide broadcasts or system events, are messages sent by
the Android operating system to notify various system components and applications about specific
events or changes occurring on the device. These broadcasts serve as a means of communication
between different parts of the system and allow components to respond to and act upon these
events.
System broadcasts are predefined by the Android system and cover a wide range of events and
scenarios. Some examples of system broadcasts include:
 Device boot completed: Sent when the device finishes booting up and becomes fully
operational.
 Screen turned on/off: Sent when the device's screen is turned on or off.
 Battery status changes: Sent when the device's battery level or charging status changes, such as
low battery or power connected/disconnected.
 Network connectivity changes: Sent when the device's network connectivity status changes,
such as connecting to a network or losing network connectivity.
 Timezone changes: Sent when the device's timezone is changed.
 Package installed/uninstalled: Sent when an application package is installed or uninstalled on
the device.
Incoming call: Sent when there is an incoming phone call.
Device shutdown: Sent when the device is about to shut down.

You might also like