0% found this document useful (0 votes)
30 views15 pages

Mobile Application Development-Ppt2

The document outlines the anatomy of an Android application, detailing its components such as Activities, Fragments, Services, Broadcast Receivers, and Content Providers. It also explains key Android terminologies, the lifecycle of Activities, the use of Intents for communication, and the significance of the AndroidManifest.xml file for declaring app components and permissions. Additionally, it covers the types of services, intent filters, and the process for requesting permissions at runtime.

Uploaded by

mojanabi84
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)
30 views15 pages

Mobile Application Development-Ppt2

The document outlines the anatomy of an Android application, detailing its components such as Activities, Fragments, Services, Broadcast Receivers, and Content Providers. It also explains key Android terminologies, the lifecycle of Activities, the use of Intents for communication, and the significance of the AndroidManifest.xml file for declaring app components and permissions. Additionally, it covers the types of services, intent filters, and the process for requesting permissions at runtime.

Uploaded by

mojanabi84
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/ 15

MOBILE APPLICATION

DEVELOPMENT
UNIT 2
Anatomy of an Android Application
An Android application consists of the following parts:
• Activities: Represents a single screen in the app.
• Fragments: Subsections of activities that allow for more modular
design.
• Services: Used for long-running operations in the background.
• Broadcast Receivers: Components that respond to system-wide
broadcast announcements.
• Content Providers: Manages shared data between apps
Additionally…
• Resource Files: Images, layouts (XML files), strings, colors, and
dimensions used to define the visual and functional aspects.
• AndroidManifest.xml: Declares app components, permissions, and
other critical app configurations.
• Gradle Files: Automate the building process, handling dependencies
and app configurations.
Android Terminologies
• Activity: Represents a user interface screen in an app.
• Intent: A messaging object to request an action from another app
component.
• Fragment: A modular part of an activity, enabling UI reusability.
• View: Basic building block of the user interface.
• Layout: Arranges views in a specific format (e.g., LinearLayout,
ConstraintLayout).
Application Context

•The Context is a handle to the environment in which an app is running.

•Application Context:
•A global context that persists throughout the app's lifecycle.
•Useful for accessing app-wide resources like themes, databases, or preferences.
Example

Context context = getApplicationContext();


Activities

•An Activity is a single, focused thing the user can do.

•Lifecycle of an Activity:
•onCreate(): Initializes the activity.
•onStart(): Activity becomes visible.
•onResume(): Activity is in the foreground and interacts with the user.
•onPause(): Another activity is partially visible.
•onStop(): Activity is no longer visible.
•onDestroy(): Activity is being destroyed.

Example:
Login Screen → Home Screen → Settings Page (each is an activity).
Services
•Services are used for background tasks without a user interface.

Types of Services:

•Started Service: Runs until it stops (e.g., playing music).


•Bound Service: Tied to a component, running only as long as it's bound (e.g., fetching data for a UI componen
•Foreground Service: Continues running with a notification (e.g., file download).

Example Code for Service:


public class MyService extends Service {
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Task to perform
return START_STICKY;
}
}
Intents

•Intents allow communication between different app components.

Explicit Intent:

•Targets a specific component.

Example: Navigating from one activity to another.

Intent intent = new Intent(this, SecondActivity.class);


startActivity(intent);
• Implicit Intent:Lets Android decide which app can handle the action.

Example: Sharing text via another app

Intent intent = new Intent(Intent.ACTION_SEND);


intent.putExtra(Intent.EXTRA_TEXT, "Hello!");
intent.setType("text/plain");
startActivity(intent);
Receiving and Broadcasting Intents

Broadcast Receivers: Listen for system-wide broadcasts (e.g., battery low).

Example of a receiver

public class MyReceiver extends BroadcastReceiver {


@Override
public void onReceive(Context context, Intent intent) {
// Handle the broadcast
}
}

•Broadcasting Intents: Apps can also send broadcasts to share information.


Android Manifest File and Its Common Settings
The AndroidManifest.xml file:
•Declares activities, services, receivers, and providers.
•Specifies permissions the app needs.

(
•Defines the app's entry point <intent-filter> with MAIN and LAUNCHER actions ).
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">
<application
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Using Intent Filter
• Used in the manifest to define what intents an activity, service, or receiver
can handle.
Example:
<activity android:name=".WebViewActivity">
<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" android:host="www.example.com" />
</intent-filter>
</activity>
Permissions
• Apps must request permissions for accessing sensitive data or
hardware.
• Normal Permissions: Automatically granted (e.g., Internet access).
• Dangerous Permissions: Require user approval (e.g., location,
camera).
Example of Permission in Manifest:
<uses-permission android:name="android.permission.CAMERA" />
Requesting Permission at Runtime:
Example code:
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,new String[]{Manifest.permission.CAMERA}, 1);
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy