Applications
I Collection of components and resources
VJ1229, Mobile Device Applications I Packaged in an apk file (Android Package)
I Protected:
Application Structure • Unique VM
• Unique user ID
• Needs permissions for certain tasks
©2025, Juan Miguel Vilar Torres
1/1 2/22
Types of Components Activities
I Activities I Single screen with a user interface
I Services I A typical application is a collection of activities:
• Loosely coupled
I Content providers
• One is designed as the “main” activity
I Broadcast receivers • Can be started from other applications. E.g., mail
I Sync adapters • The system keeps a stack of activities é the back stack
3/22 4/22
Services Content Providers
I Manage a set of data from the application
I Components that run in the background
I Provide access independent of the type of storage (SQLite
I For long-running operations
database, web, file in the SD card, etc.)
I Do not provide user interface
I Also useful for storing app private data
I E.g.: music player, downloader from the web
I E.g.: contact information
5/22 6/22
Broadcast Receivers Sync Adapters
I Responds to system-wide broadcast announcements:
• From the system: screen has turned off, battery is low, a
picture has been captured I Synchronize local data with cloud servers
• From applications: e.g. a file has been downloaded
I Examples: Google Calendar and Contact apps
I They can use notifications
I Usually they perform almost no work and start other
components
7/22 8/22
The Manifest Example
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="[Link]
xmlns:tools="[Link]
<uses-permission android:name="[Link]" />
I XML file in the root directory of the application
<application
app/src/main/[Link] android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
I Holds important information android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
I Must list all the components of the application android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
I Automatically updated by Android Studio android:theme="@style/[Link]"
tools:targetApi="31">
<activity .../>
<activity .../>
<activity ...>
</activity>
</application>
</manifest>
9/22 10/22
Activities in the Manifest Component Activation
I The main entry to the program is marked with an intent filter:
<activity I Loose coupling of components allows their use from different
android:name=".MainActivity"
android:exported="true"> applications
<intent-filter>
<action android:name="[Link]" /> I No need to create a component to take photos in our
<category android:name="[Link]" /> application
</intent-filter>
</activity> I Only possible with enough permissions
I The rest of the activities need no special information, but I The user must approve permissions
must be listed:
<activity I Communication via intents
android:name=".[Link]"
android:exported="false" />
11/22 12/22
Intents Uses of Intents
I Message objects for requesting actions I To start an activity: used for passing the information and for
receiving the result, if any
I An intent carries:
I To start a service or bind to it
• Required action
• Additional information I To deliver a broadcast
13/22 14/22
Types of Intents Information of Intents
I Component name: optional é explicit/implicit
I Explicit:
• Explicitly request the component to start I Action: eg ACTION_VIEW, ACTION_SEND, ACTION_DIAL
• Typical for starting activities or services in the same application I Data: an URI and, possibly, a MIME type
I Implicit: I Category: kind of component that should treat the intent, eg
• Request a general action to perform CATEGORY_LAUNCHER
• The system finds the appropriate component I Extras: arbitrary information in form of key-value pairs
15/22 16/22
Starting an Activity Recovering the Information
I Simplest form:
val intent = Intent(this, GameActivity::[Link])
startActivity(intent)
I Adding information: I The information is available through the intent attribute of
val intent = Intent(this, GameActivity::[Link]) the Activity
[Link](GameActivity.NUMBER_OF_COLORS,
numberOfColors) I It is usually read within the onCreate function
// ... other extras
startActivity(intent) val numberOfColors = [Link](NUMBER_OF_COLORS, 0)
I In GameActivity:
companion object {
const val NUMBER_OF_COLORS = "NUMBER_OF_COLORS"
// ... other constants
}
17/22 18/22
Creating Implicit Intents Creating Implicit Intents (2)
I Implicit Intents declare the action that must be carried out I If necessary, additional information can be added with
putExtra:
I The data attribute contains the URI to which the action is
targeted val intent = Intent(Intent.ACTION_SEND).apply {
type = "*/*" // mime type
val phoneNumber = "666777888" putExtra(Intent.EXTRA_EMAIL, addresses)
val intent = Intent(Intent.ACTION_DIAL).apply { putExtra(Intent.EXTRA_SUBJECT, subject)
data = [Link]("[Link] putExtra(Intent.EXTRA_STREAM, attachment)
} }
19/22 20/22
Using Implicit Intents Further Information
I It is necessary to check if there is an activity that can process
the intent: I Chapter “Inspecting your Manifest”
if ([Link](packageManager) != null) { I Chapter “Implementing Multiple Activities”
startActivity(intent)
}
21/22 22/22