0% found this document useful (0 votes)
0 views

applicationStructure.8

The document outlines the structure and components of mobile device applications, specifically focusing on Android applications packaged in APK files. It details various components such as activities, services, content providers, broadcast receivers, and sync adapters, along with their functions and how they interact. Additionally, it explains the role of the Android Manifest file and the use of intents for component communication and activation.

Uploaded by

al397126
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)
0 views

applicationStructure.8

The document outlines the structure and components of mobile device applications, specifically focusing on Android applications packaged in APK files. It details various components such as activities, services, content providers, broadcast receivers, and sync adapters, along with their functions and how they interact. Additionally, it explains the role of the Android Manifest file and the use of intents for component communication and activation.

Uploaded by

al397126
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/ 3

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="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">

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


I XML file in the root directory of the application
<application
app/src/main/AndroidManifest.xml 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/Theme.FortUJI"
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="android.intent.action.MAIN" /> I No need to create a component to take photos in our
<category android:name="android.intent.category.LAUNCHER" /> 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=".newsActivity.NewsActivity"
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::class.java)
startActivity(intent)

I Adding information: I The information is available through the intent attribute of


val intent = Intent(this, GameActivity::class.java) the Activity
intent.putExtra(GameActivity.NUMBER_OF_COLORS,
numberOfColors) I It is usually read within the onCreate function
// ... other extras
startActivity(intent) val numberOfColors = intent.getIntExtra(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 = Uri.parse("tel:$phoneNumber") 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 (intent.resolveActivity(packageManager) != null) { I Chapter “Implementing Multiple Activities”


startActivity(intent)
}

21/22 22/22

You might also like