0% found this document useful (0 votes)
8 views14 pages

Android

The document provides answers to Unit 2 of a Mobile Application Development question bank, focusing on fundamental Android concepts such as Context, Activity, Fragment, Intent, and Services. It explains the lifecycle of activities, the purpose of the Android Manifest file, and the differences between explicit and implicit intents. Additionally, it discusses the role of Fragments in UI organization and the steps for transitioning between activities using intents.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views14 pages

Android

The document provides answers to Unit 2 of a Mobile Application Development question bank, focusing on fundamental Android concepts such as Context, Activity, Fragment, Intent, and Services. It explains the lifecycle of activities, the purpose of the Android Manifest file, and the differences between explicit and implicit intents. Additionally, it discusses the role of Fragments in UI organization and the steps for transitioning between activities using intents.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Here are the answers for Unit 2 of the Mobile Application Development question bank, focusing

on easier concepts in Android:

UNIT-II
2 Marks Questions
1.​ What is a Context? Give an example. A Context in Android is an interface that provides
access to application-specific resources and classes, as well as up-calls for
application-level operations such as launching activities, broadcasting and receiving
intents, etc. An example is getApplicationContext() which returns the context for the entire
application.
2.​ What is an Activity? Give an example. An Activity is a single screen with a user
interface in an Android application. It represents a single focus point for the user. An
example is the MainActivity which is typically the first screen a user sees when opening
an app.
3.​ What is a Fragment? Specify its use. A Fragment is a modular section of an Android
Activity that has its own lifecycle, input events, and can be added or removed while the
activity is running. Its use is to provide more flexible UI design, especially for tablets,
allowing multiple UI components to be combined into a single activity.
4.​ What is a Intent? Give an example. An Intent is a messaging object that you can use to
request an action from another app component. An example is starting a new activity:
Intent intent = new Intent(this, SecondActivity.class); startActivity(intent);.
5.​ What are services? Give an example. Services are application components that can
perform long-running operations in the background, without a user interface. They are
useful for tasks that don't require user interaction, such as playing music in the
background or performing network operations. An example is a music player service that
continues to play music even when the user navigates away from the app.
6.​ Differentiate onCreate() and onStart() methods in the Android activity lifecycle.
onCreate() is called when the activity is first created, and it's where you typically perform
static setup like creating views and binding data to lists. onStart() is called when the
activity becomes visible to the user.
7.​ What is the purpose of onPause and onResume() method in the activity lifecycle?
onPause() is called when the system is about to resume a previous activity or when the
activity is no longer in the foreground. onResume() is called when the activity will start
interacting with the user, and it's usually where you restart animations, open
exclusive-access devices (like the camera), or reinitialize components that were released
in onPause().
8.​ How can you save and restore the state of an activity during its lifecycle? You can
save the state of an activity by overriding the onSaveInstanceState(Bundle outState)
method, where you put data into the Bundle. To restore the state, you retrieve data from
the Bundle in the onCreate(Bundle savedInstanceState) method.
9.​ What are the two types of Intents in Android, and how do they differ? The two types
of Intents are explicit and implicit.
○​ Explicit Intents: Specify the component to start by name. They are used when you
know the exact activity or component you want to launch within your own app.
○​ Implicit Intents: Do not name a specific component, but instead declare a general
action to perform, allowing the system to find a suitable component to handle it.
They are used to request an action that can be performed by multiple apps.
10.​What is the purpose of intent filters? Intent filters are used to declare the capabilities of
an app component (like an activity or service) to the Android system. They specify the
types of intents that a component can respond to, allowing other applications to launch
that component implicitly.
11.​How do you initiate an activity transition using intents? You initiate an activity
transition using intents by creating an Intent object that specifies the target activity and
then calling startActivity(intent).
12.​What is the purpose of the Android Manifest file? The Android Manifest file
(AndroidManifest.xml) describes the fundamental characteristics of the app and defines
each of its components. It declares the app's packages, components (activities, services,
broadcast receivers, content providers), permissions, and hardware/software features it
needs.
13.​Name two essential components that must be declared in the Android Manifest file
for an Android application. Two essential components that must be declared in the
Android Manifest file are activities and application permissions.
14.​What is the purpose of registering permissions in an Android application? The
purpose of registering permissions in an Android application is to protect user privacy and
device resources. It allows the app to request access to sensitive data or features, and it
informs the user about what capabilities the app requires.
15.​How do you declare a permission in the AndroidManifest.xml file? You declare a
permission in the AndroidManifest.xml file using the <uses-permission> tag, for example:
<uses-permission android:name="android.permission.INTERNET"/>.
16.​Differentiate normal and dangerous permissions in Android. Provide examples of
each.
○​ Normal permissions are those that do not pose a direct risk to the user's privacy
or the device's operation. They are granted automatically by the system without
explicit user approval. Example: android.permission.ACCESS_NETWORK_STATE.
○​ Dangerous permissions are those that give the app access to sensitive user data
or device resources that could affect the user's privacy or the device's operation.
These require explicit user consent at runtime. Example:
android.permission.CAMERA, android.permission.READ_CONTACTS.
17.​What is the purpose of registering activities in the AndroidManifest.xml file? The
purpose of registering activities in the AndroidManifest.xml file is to inform the Android
system about the activities that belong to the application and to make them accessible to
the system and other applications.
18.​How do you declare an activity in the AndroidManifest.xml file? You declare an
activity in the AndroidManifest.xml file using the <activity> tag within the <application>
tag, for example: <activity android:name=".MainActivity"></activity>.

4-6 Marks Questions


1.​ How does the application context in Android facilitate managing
application-specific configuration details and operations across multiple
components? The application context in Android provides a global, application-wide
context that can be accessed by all components of the application. It facilitates managing
application-specific configuration details and operations by:
○​ Providing access to resources: It allows components to access application
resources like strings, colors, drawables, and layouts.
○​ Managing global state: It can hold application-wide state or data that needs to be
shared across multiple activities or services without passing them explicitly through
intents.
○​ Lifecycle independence: Unlike activity contexts, the application context is not tied
to the lifecycle of a specific activity. This means it persists for the entire duration of
the application's process, making it suitable for operations that need to outlive
individual activities, such as starting background services or accessing content
providers.
○​ Reduced memory leaks: Using the application context for long-lived operations
can help prevent memory leaks that might occur if an activity context were used
and the activity was destroyed.
2.​ Why is the Activity class considered core to any Android application, and how does
it contribute to the development of user interfaces? The Activity class is considered
core to any Android application because it represents a single, focused thing that the user
can do. It serves as the primary entry point for user interaction and is responsible for
creating and managing the user interface. It contributes to UI development in several
ways:
○​ Hosts the UI: Activities are the containers for the user interface elements (views
and view groups) that users see and interact with.
○​ Manages UI lifecycle: The Activity class provides a well-defined lifecycle
(onCreate, onStart, onResume, onPause, onStop, onDestroy) that developers use
to manage the state of their UI components and data. This ensures that the UI is
properly initialized, updated, and cleaned up as the user navigates through the app.
○​ Handles user input: Activities receive and process user input events, such as
touches, clicks, and key presses, allowing developers to implement interactive UI
behaviors.
○​ Facilitates navigation: Activities are the fundamental building blocks for navigation
within an Android application. Intents are used to start new activities, allowing users
to move between different screens and functionalities.
○​ Provides access to resources: Activities provide a context that allows access to
application resources (layouts, strings, images), which are essential for building a
rich and consistent user interface.
3.​ Define the Activity class in Android and its role in application development. The
Activity class in Android is a fundamental component that represents a single screen with
a user interface. It acts as an entry point for user interaction and provides the window in
which the app draws its UI. Its role in application development is crucial:
○​ User Interface Presentation: The Activity is responsible for presenting the user
interface to the user. It inflates layout XML files and manages the various UI
widgets (buttons, text views, etc.).
○​ User Interaction Handling: It handles user interactions such as button clicks,
touch events, and other input, allowing the application to respond dynamically.
○​ Lifecycle Management: The Activity class defines a lifecycle (e.g., onCreate(),
onStart(), onResume(), onPause(), onStop(), onDestroy()) that the Android system
manages. Developers override these methods to manage the state of the activity
and its resources appropriately.
○​ Application Flow Control: Activities are used to control the flow of the application.
By starting new activities and managing the back stack, developers define how
users navigate through the app's different screens.
○​ Data Management: Activities often interact with data sources, whether it's local
storage, databases, or network services, to display and manipulate information.
○​ Integration with System Services: Activities can interact with various Android
system services, such as the camera, location services, or notifications, to provide
richer functionality.
4.​ Describe the various states an activity goes through during its lifecycle. An Android
activity can go through several states during its lifecycle:
○​ Created (onCreate()): The activity is being created. This is where you perform
basic application startup logic that should happen once for the entire life of the
activity, like setting the content view.
○​ Started (onStart()): The activity is becoming visible to the user.
○​ Resumed (onResume()): The activity is in the foreground and the user can interact
with it. This is the state where the activity spends most of its time.
○​ Paused (onPause()): The activity is partially obscured by another activity. The
activity is still visible, but not in focus.
○​ Stopped (onStop()): The activity is no longer visible to the user. This can happen if
another activity covers it completely or if the user navigates away.
○​ Destroyed (onDestroy()): The activity is being destroyed and removed from
memory. This can happen due to user action (e.g., pressing back button) or system
action (e.g., configuration change, low memory).
5.​ Describe the sequence of lifecycle methods called when an activity is launched for
the first time. When an activity is launched for the first time, the following sequence of
lifecycle methods are called:
1.​ onCreate(): This is the first method called when the activity is created. It's used for
one-time setup, like inflating the layout.
2.​ onStart(): The activity becomes visible to the user.
3.​ onResume(): The activity comes to the foreground and becomes interactive.
6.​ Describe the role of Fragments in organizing UI components in Android
applications. Fragments play a crucial role in organizing UI components in Android
applications by:
○​ Modularity: Fragments allow developers to break down a complex UI into smaller,
reusable, and self-contained modules. Each fragment can manage its own layout
and behavior.
○​ Reusability: The same fragment can be used in multiple activities or in different
parts of the same activity, promoting code reusability and reducing duplication.
○​ Adaptive Layouts: Fragments are essential for creating flexible UI designs that
can adapt to different screen sizes and orientations, especially for tablets. Multiple
fragments can be displayed side-by-side on larger screens, while on smaller
screens, they might be displayed individually in separate activities.
○​ Simplified UI Management: By encapsulating specific UI components and their
logic within a fragment, it simplifies the overall management of the user interface
within an activity.
○​ Back Stack Management: Fragments have their own back stack, allowing for more
granular navigation within a single activity.
7.​ Discuss the use cases where Fragments are particularly useful compared to using
only Activities in Android development. Fragments are particularly useful in several
use cases where using only Activities would be less efficient or more complex:
○​ Tablet Layouts: For applications targeting tablets, fragments enable the creation of
multi-pane layouts where different sections of the UI can be displayed
simultaneously on the same screen (e.g., a list on one side and details on the
other).
○​ Reusable UI Components: If you have a UI component (e.g., a custom dialog, a
set of input fields, or a navigation pane) that needs to be used in multiple activities,
creating it as a fragment allows for easy reuse without duplicating code.
○​ Flexible UI Design: Fragments offer greater flexibility in arranging UI elements
dynamically. You can add, remove, replace, and animate fragments at runtime
based on user interactions or device configuration.
○​ Swappable Content: For applications with tabbed interfaces or swipeable views
(like ViewPager), fragments are ideal for managing the content of each tab or page.
○​ Complex UI with Independent Modules: When an activity has a very complex UI
with distinct, independent sections, using fragments for each section can improve
code organization and maintainability.
○​ Handling Configuration Changes: Fragments can be set to retain their instance
across configuration changes (like screen rotation), which can be useful for
preserving data that doesn't need to be recreated.
8.​ Explain the difference between explicit and implicit intents in Android. Provide
examples of when each type would be used for activity transitions. Explicit Intents:
○​ Definition: An explicit intent specifies the component (e.g., a specific Activity,
Service, or Broadcast Receiver) to be started by its fully qualified class name.
○​ Use Case: They are used when you know the exact component you want to launch
within your own application.
○​ Example: Launching a SecondActivity from MainActivity within the same app:​
// In MainActivity.java​
Intent intent = new Intent(this, SecondActivity.class);​
startActivity(intent);​

Implicit Intents:
○​ Definition: An implicit intent does not name a specific component but instead
declares a general action to perform (e.g., view, edit, dial) and optional data. The
Android system then finds the appropriate component(s) that can perform that
action.
○​ Use Case: They are used when you want to perform an action, and you don't
necessarily know which specific application component will handle it, or you want to
give the user a choice of applications.
○​ Example: Opening a web page in a browser:​
// In your Activity.java​
String url = "http://www.google.com";​
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(url));​
startActivity(intent);​

9.​ Describe the steps involved in transitioning from one activity to another using an
explicit intent. Include necessary code snippets or explanations. To transition from
one activity to another using an explicit intent:
1.​ Create an Intent object: Instantiate an Intent object, passing the current Context
(usually this if you're in an Activity) and the .class object of the target Activity.​
// In your current Activity (e.g., MainActivity.java)​
Intent intent = new Intent(MainActivity.this,
SecondActivity.class);​

2.​ Start the new Activity: Call the startActivity() method, passing the Intent object
you just created.​
// In your current Activity​
startActivity(intent);​

3.​ Optional: Pass data (using putExtra): If you need to pass data to the new activity,
you can use putExtra() methods on the Intent object before starting the activity.​
// In your current Activity​
intent.putExtra("key_name", "value_to_pass"); // Example:
passing a String​
startActivity(intent);​

4.​ Optional: Receive data in the new Activity: In the onCreate() method of the
SecondActivity, you can retrieve the passed data using getIntent().getExtras() or
specific get...Extra() methods.​
// In SecondActivity.java​
@Override​
protected void onCreate(Bundle savedInstanceState) {​
super.onCreate(savedInstanceState);​
setContentView(R.layout.activity_second);​

// Retrieve data​
if (getIntent().hasExtra("key_name")) {​
String receivedData =
getIntent().getStringExtra("key_name");​
// Use the receivedData​
}​
}​

5.​ Optional: Finish the current activity: If you don't want the user to be able to
return to the current activity by pressing the back button, you can call finish() after
startActivity().​
// In your current Activity​
startActivity(intent);​
finish(); // Closes the current activity​

10.​What is the role of intent filters in Android? How are they used to enable
inter-application communication and activity resolution? Provide an example to
demonstrate their usage. Role of Intent Filters: Intent filters are declarations within an
Android app's manifest file (AndroidManifest.xml) that inform the Android system about
the types of intents that a particular app component (Activity, Service, or Broadcast
Receiver) is capable of handling. They essentially act as a "filter" for incoming implicit
intents, allowing the system to match an intent with the appropriate component that can
fulfill the requested action.Enabling Inter-Application Communication and Activity
Resolution:
○​ Inter-application Communication: Intent filters are fundamental for enabling
seamless communication between different applications on an Android device.
When an app sends an implicit intent (an intent that doesn't specify an explicit
component), the Android system looks for components across all installed
applications that have an intent filter matching the action, data, and category of the
intent. This allows apps to request services or share data with other apps without
needing to know the other app's internal structure.
○​ Activity Resolution: When an implicit intent is sent, the system uses intent filters
to "resolve" which activity (or other component) should handle the intent. If multiple
components match, the system might present a chooser dialog to the user, allowing
them to select which app to use. If only one component matches, that component is
launched directly.
Example to Demonstrate Usage: Consider an application that wants to share text
content. Another application can declare an intent filter in its AndroidManifest.xml to
indicate that it can receive and display text.App A (Sender) - Java Code:// In
App A's Activity​
Intent shareIntent = new Intent(Intent.ACTION_SEND);​
shareIntent.setType("text/plain"); // Specify the MIME type
of the data​
shareIntent.putExtra(Intent.EXTRA_TEXT, "Hello from App A!");
// The data to share​
startActivity(Intent.createChooser(shareIntent, "Share text
using..."));​
App B (Receiver) - AndroidManifest.xml:<activity
android:name=".ShareReceiverActivity">​
<intent-filter>​
<action android:name="android.intent.action.SEND" />​
<category
android:name="android.intent.category.DEFAULT" />​
<data android:mimeType="text/plain" />​
</intent-filter>​
</activity>​
Explanation:
○​ Sender (App A): Creates an implicit intent with ACTION_SEND and sets the data
type to text/plain along with the text to share.
○​ Receiver (App B): The ShareReceiverActivity in App B has an intent-filter that
explicitly states it can handle intents with ACTION_SEND (<action
android:name="android.intent.action.SEND" />) and that operate on text/plain data
(<data android:mimeType="text/plain" />). The <category
android:name="android.intent.category.DEFAULT" /> is crucial for allowing the
activity to be launched by an implicit intent.
○​ When App A sends the intent, the Android system finds App B's
ShareReceiverActivity because its intent filter matches the intent's action and data
type. The user will then be presented with a chooser, including App B, among other
apps capable of sharing text.
11.​Describe the use cases where you would prefer services in an Android application.
You would prefer using services in an Android application for operations that need to run
in the background without a user interface, and often for extended periods. Key use cases
include:
○​ Playing Music in the Background: A music player app might use a service to
continue playing audio even when the user navigates away from the main activity or
uses another app.
○​ Performing Network Operations: Downloading large files, syncing data with a
server, or fetching regular updates can be handled by a service, ensuring that these
operations complete even if the UI is no longer active.
○​ Handling Long-Running Tasks: Any task that requires significant processing time
and shouldn't block the UI thread (like image processing, data compression, or
complex calculations) is a good candidate for a service.
○​ Implementing Alarms and Notifications: Services can be used in conjunction
with AlarmManager to schedule recurring tasks or to show persistent notifications
(e.g., a fitness tracker that continuously monitors steps).
○​ Providing Content to Other Applications: If your application needs to provide its
data to other applications (e.g., a weather app providing weather updates), a
service can expose this functionality.
○​ GPS Tracking: An application that continuously tracks the user's location, even
when the app is not in the foreground, would typically use a service.
12.​Describe the purpose of Android Manifest File. Specify the purposes for which this
file is used by the Android System. The Android Manifest file (AndroidManifest.xml) is a
crucial XML file that resides at the root of every Android application project. It serves as a
contract between your application and the Android operating system, providing essential
information that the system needs to run and interact with your app.Purposes for which
this file is used by the Android System:
○​ Application's Package Name: It declares the Java package name for the
application, which serves as a unique identifier for the app on the device and in the
Google Play Store.
○​ Application Components: It declares all of the application's
components—activities, services, broadcast receivers, and content providers. Each
component must be explicitly declared for the system to recognize and launch
them.
○​ Permissions: It declares the permissions that the application needs to access
protected parts of the system or other applications (e.g., Internet access, camera,
contacts). It also declares any custom permissions that other applications must
have to interact with components of this app.
○​ Hardware and Software Features: It declares the hardware and software features
that the application requires or prefers (e.g., android.hardware.camera,
android.software.app_widgets). This information is used by the Google Play Store
to filter apps that are not compatible with a user's device.
○​ API Level Support: It declares the minimum API level that the application requires
(minSdkVersion) and the API level it's designed to run on (targetSdkVersion). This
helps the system determine compatibility and apply appropriate behaviors.
○​ Intent Filters: It specifies which types of intents each application component can
respond to. This is crucial for enabling implicit intents and allowing inter-application
communication.
○​ Application Metadata: It can include various metadata about the application, such
as its icon, label, theme, and other configuration options.
○​ Entry Points: It defines the main entry points for the application, typically
specifying which activity should be launched when the user taps the app icon.
13.​Provide a sample AndroidManifest.xml​
<?xml version="1.0" encoding="utf-8"?>​
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"​
package="com.example.myfirstapp">​

<uses-permission android:name="android.permission.INTERNET" />​
<uses-permission android:name="android.permission.CAMERA" />​

<application​
android:allowBackup="true"​
android:icon="@mipmap/ic_launcher"​
android:label="@string/app_name"​
android:roundIcon="@mipmap/ic_launcher_round"​
android:supportsRtl="true"​
android:theme="@style/Theme.MyFirstApp">​

<activity​
android:name=".MainActivity"​
android:exported="true">​
<intent-filter>​
<action android:name="android.intent.action.MAIN"
/>​
<category
android:name="android.intent.category.LAUNCHER" />​
</intent-filter>​
</activity>​

<activity android:name=".SecondActivity" />​

<service android:name=".MyBackgroundService" />​

<receiver android:name=".MyBroadcastReceiver"
android:exported="true">​
<intent-filter>​
<action
android:name="android.intent.action.BOOT_COMPLETED" />​
</intent-filter>​
</receiver>​

<provider​
android:name=".MyContentProvider"​
android:authorities="com.example.myfirstapp.provider"​
android:exported="false" />​

</application>​
</manifest>​

14.​List and explain any 6 important tags of AndroidManifest.xml Here are 6 important
tags found in the AndroidManifest.xml file:
1.​ <manifest>: This is the root element of the AndroidManifest.xml file. It describes
the characteristics of the application's package. It contains attributes like package
(the unique package name for the application) and declares the XML namespaces
used.
2.​ <application>: This tag is a sub-element of <manifest> and declares the
application as a whole. It contains attributes that apply to all components of the
application, such as android:icon (the default icon for all application components),
android:label (a user-readable label for the application), android:allowBackup
(whether the application is allowed to participate in the backup and restore
infrastructure), and android:theme (the default theme for all activities). It also serves
as a container for declarations of the application's components.
3.​ <activity>: This tag declares an activity component. Every activity used in the
application must be declared within this tag. Key attributes include android:name
(the class name of the activity) and android:exported (whether the activity can be
launched by components outside this application). It often contains <intent-filter>
elements.
4.​ <uses-permission>: This tag declares a system permission that the user must
grant for the application to operate correctly. For example, <uses-permission
android:name="android.permission.INTERNET" /> declares that the app needs
internet access.
5.​ <intent-filter>: This tag is a sub-element of <activity>, <service>, or <receiver> and
specifies the types of intents that the parent component can respond to. It typically
contains <action>, <category>, and <data> sub-elements to define the filter criteria.
6.​ <service>: This tag declares a service component. Services perform long-running
operations in the background without a user interface. Similar to activities, they
require an android:name attribute specifying the service class.
7.​ <uses-feature>: This tag declares a single hardware or software feature that the
application requires or prefers to be present on the device. For instance,
<uses-feature android:name="android.hardware.camera" android:required="true" />
indicates that a camera is a mandatory feature. (I included 7 as an extra, but the
request was for 6).
15.​How does the Android permission model ensure the security of user data and
device resources? Discuss the significance of runtime permissions in this context.
The Android permission model ensures the security of user data and device resources by:
○​ Granular Control: It categorizes permissions based on the sensitivity of the data or
resource they protect.
○​ User Consent: For sensitive (dangerous) permissions, it requires explicit user
consent, giving users control over their data and device.
○​ Isolation: Each app runs in its own sandbox, limiting its access to system
resources and other apps' data unless explicitly granted permissions.
Significance of Runtime Permissions: Runtime permissions, introduced in
Android 6.0 (API level 23) Marshmallow, are highly significant in enhancing security
and user privacy:
○​ User Empowerment: Before Marshmallow, users had to grant all permissions at
installation time, often without fully understanding the implications. Runtime
permissions allow users to grant or deny dangerous permissions while the app is
running, providing more transparency and control. This means users can decide on
a case-by-case basis whether they trust an app with specific sensitive data or
features.
○​ Contextual Granting: Apps can request permissions only when they are actually
needed in context. For example, a camera app might only request camera
permission when the user tries to take a photo, rather than at app installation. This
improves the user experience by not overwhelming them with all permission
requests upfront.
○​ Revocability: Users can revoke previously granted runtime permissions at any
time through the device settings, even after installation. This provides ongoing
control and allows users to adapt their privacy settings if they change their minds or
no longer trust an app.
○​ Enhanced Security: By making it harder for malicious apps to gain broad access
without user awareness, runtime permissions significantly reduce the attack surface
and make the Android platform more secure. Apps are encouraged to request only
the permissions they truly need, following the principle of least privilege.
16.​Explain the concept of permission groups in Android and provide examples of
permission groups and the permissions they include. Concept of Permission
Groups: In Android, permissions are organized into permission groups to simplify the
user experience when granting permissions. When a user grants permission to an app at
runtime, they are not granting a single permission, but rather the permission group that
permission belongs to. If an app requests another permission that is part of the same
group, the system automatically grants it without prompting the user again. This is
because it's assumed that if a user trusts an app with one sensitive permission in a group,
they likely trust it with others in the same group.Examples of Permission Groups and
the Permissions they Include: Here are some common permission groups and
examples of permissions they contain:
1.​ CALENDAR Group (android.permission-group.CALENDAR)
■​ android.permission.READ_CALENDAR: Allows an application to read the
user's calendar data.
■​ android.permission.WRITE_CALENDAR: Allows an application to write the
user's calendar data.
2.​ CAMERA Group (android.permission-group.CAMERA)
■​ android.permission.CAMERA: Required to be able to access the camera
device.
3.​ CONTACTS Group (android.permission-group.CONTACTS)
■​ android.permission.READ_CONTACTS: Allows an application to read the
user's contacts data.
■​ android.permission.WRITE_CONTACTS: Allows an application to write the
user's contacts data.
■​ android.permission.GET_ACCOUNTS: Allows access to the list of accounts
in the Accounts Service.
4.​ LOCATION Group (android.permission-group.LOCATION)
■​ android.permission.ACCESS_FINE_LOCATION: Allows an app to access
precise location (e.g., GPS).
■​ android.permission.ACCESS_COARSE_LOCATION: Allows an app to
access approximate location (e.g., Wi-Fi, cellular).
5.​ MICROPHONE Group (android.permission-group.MICROPHONE)
■​ android.permission.RECORD_AUDIO: Allows an application to record audio.
6.​ PHONE Group (android.permission-group.PHONE)
■​ android.permission.READ_PHONE_STATE: Allows read-only access to
phone state, including the phone number of the device, current cellular
network information, the status of any ongoing calls, and a list of any
PhoneAccounts registered on the device.
■​ android.permission.CALL_PHONE: Allows an application to initiate a phone
call without going through the Dialer user interface.
■​ android.permission.READ_CALL_LOG: Allows an application to read the
user's call log.
■​ android.permission.WRITE_CALL_LOG: Allows an application to write to the
user's call log.
■​ android.permission.ADD_VOICEMAIL: Allows an application to add
voicemails into the system.
■​ android.permission.USE_SIP: Allows an application to use SIP (Session
Initiation Protocol) in order to make/receive Internet calls.
■​ android.permission.PROCESS_OUTGOING_CALLS: Allows an application to
see the number dialed during an outgoing call with the option to redirect the
call to a different number or abort the call altogether.
17.​Describe the role of intent filters in the registration of activities in the
AndroidManifest.xml file. Provide an example. The role of intent filters in the
registration of activities in the AndroidManifest.xml file is to specify what kinds of intents
an activity can respond to. When you declare an activity in the manifest, adding an
intent-filter essentially publishes the activity's capabilities to the Android system. This
allows the system (and other applications) to discover and launch this activity implicitly,
without needing to know its exact class name.How they work:
○​ An intent-filter contains <action>, <category>, and <data> elements.
○​ <action>: Declares the action the activity can perform (e.g.,
android.intent.action.MAIN, android.intent.action.VIEW).
○​ <category>: Provides additional context about the kind of component that can
handle the intent (e.g., android.intent.category.LAUNCHER for an app's main entry
point, android.intent.category.DEFAULT for general activities that can be targeted
by implicit intents).
○​ <data>: Specifies the type of data (MIME type) and/or URI scheme that the activity
can operate on.
Example: Consider an activity named MyShareActivity that you want to be able to
receive shared text from other applications.AndroidManifest.xml:<manifest
xmlns:android="http://schemas.android.com/apk/res/android"​
package="com.example.myapp">​

<application​
android:allowBackup="true"​
android:icon="@mipmap/ic_launcher"​
android:label="@string/app_name"​
android:roundIcon="@mipmap/ic_launcher_round"​
android:supportsRtl="true"​
android:theme="@style/Theme.MyApp">​

<activity​
android:name=".MainActivity"​
android:exported="true">​
<intent-filter>​
<action
android:name="android.intent.action.MAIN" />​
<category
android:name="android.intent.category.LAUNCHER" />​
</intent-filter>​
</activity>​

<activity​
android:name=".MyShareActivity"​
android:exported="true"> <intent-filter>​
<action
android:name="android.intent.action.SEND" />​
<category
android:name="android.intent.category.DEFAULT" />​
<data android:mimeType="text/plain" />​
</intent-filter>​
</activity>​

</application>​
</manifest>​
Explanation:
○​ The MainActivity has an intent filter with ACTION_MAIN and
CATEGORY_LAUNCHER, indicating that it's the primary entry point when the user
taps the app icon.
○​ The MyShareActivity has an intent filter that declares:
■​ It can handle the android.intent.action.SEND action.
■​ It belongs to the android.intent.category.DEFAULT category (which is
essential for implicit intents).
■​ It can process data with the MIME type text/plain.
Now, if another application (e.g., a web browser or a notes app) creates an implicit intent to
share plain text:// In another app's code​
Intent shareIntent = new Intent(Intent.ACTION_SEND);​
shareIntent.setType("text/plain");​
shareIntent.putExtra(Intent.EXTRA_TEXT, "Some text to share!");​
startActivity(Intent.createChooser(shareIntent, "Share via"));​
The Android system will look at the manifest files of all installed applications. It will find
MyShareActivity because its intent filter matches the ACTION_SEND and text/plain criteria. The
user will then be given the option to choose MyApp (and specifically MyShareActivity) as a
target for sharing the text.Without the correct intent filter in the AndroidManifest.xml,
MyShareActivity would not be discoverable by implicit intents and thus couldn't receive shared
text from other applications.

You might also like