Android Activity and Intent Overview
Android Activity and Intent Overview
)
DAPARTMENT OF COMPUTER SCIENCE AND APPLICATION
Session: 2025-26
SUBJECT – Mobile Application Development
SUBJECT – Cloud Computing
TOPIC – Assignment of Mobile Application Development
SUBJECT – Cloud Computing
GUIDED BY: -
PRESENTED BY: -
DR. RAHUL HARIPRIYA ANISHA PATEL
ASSISTANT PROFESSOR MCA – 3rd Sem
1. What is an Activity in Android?
An Activity in Android is a single screen with a user interface (UI) that the
user can see and interact with. It is one of the core components of an Android
application.
Every Android app consists of one or more activities, and each activity
represents a specific task or screen, such as:
Login screen
Home screen
Settings screen
Profile screen
An Activity is a component of an Android application that provides a
screen where users can interact with the app to perform specific actions.
Example
WhatsApp:
o Login Activity
o Chat List Activity
o Chat Screen Activity
Instagram:
o Login Activity
o Feed Activity
o Profile Activity
Activity Lifecycle
Android manages activities using a lifecycle, which includes methods
like:
onCreate() – called when the activity is created
onStart() – activity becomes visible
onResume() – user can interact with it
onPause() – activity is partially hidden
onStop() – activity is no longer visible
onDestroy() – activity is destroyed
These methods help manage memory and resources efficiently
Example:
Uses of Intent
To start an Activity
To start a Service
To send data between Activities
To broadcast messages
Types of Intent
There are two main types of Intents:
1. Explicit Intent
An Explicit Intent is used when the target component is known.
Mostly used within the same application.
Example:
Intent intent = new Intent([Link], [Link]);
startActivity(intent);
Use case:
Moving from LoginActivity to HomeActivity
Opening a specific screen in your app
2. Implicit Intent
An Implicit Intent is used when the target component is not specified, and
Android chooses the best app to handle the request.
Used to perform common actions like calling, sending email, opening a
webpage.
Example:
Intent intent = new Intent(Intent.ACTION_VIEW);
[Link]([Link]("[Link]
startActivity(intent);
Use case:
Opening a website
Making a phone call
Sharing content
Additional Types
Broadcast Intent – sends messages to multiple receivers
Service Intent – used to start or bind services
Lifecycle Stage: It is called when the activity is first created. * Purpose: Its
primary purpose is to perform basic application startup logic that should
only happen once for the entire life of the activity.
Key Tasks:
o Layout Inflation: Calling setContentView(int layoutResID) to define
the activity's user interface from an XML layout file.
o UI Initialization: Initializing UI components (like buttons and text
views) and binding them to the code.
o Data Setup: Initializing class-scope variables and setting up static
data structures.
o State Restoration: Retrieving and restoring the activity's state from
the Bundle object passed as a parameter.
Major Differences
onResume() onPause()
Called when Activity becomes Called when Activity is
active and interactive partially hidden
User can interact with the Activity User cannot fully interact
Used to start or resume tasks Used to pause or stop
(animations, sensors, camera) tasks
Happens after onStart() Happens before onStop()
Activity is moving to
Activity is in the foreground
background
Example
onResume()
→ Start music, resume video, enable sensors
onPause()
→ Pause music/video, save data, release camera
@Override
protected void onResume() {
[Link]();
// Resume app functionality
}
@Override
protected void onPause() {
[Link]();
// Pause ongoing tasks
}
5. What does dp stand for in Android?
dp stands for Density-independent Pixels.
Why dp is used
Android devices have different screen sizes and pixel densities
Using dp ensures:
o Same physical size of UI elements on all screens
o Better responsive and scalable UI
How dp works
1 dp = 1 pixel on a 160 dpi (mdpi) screen
On higher density screens:
o dp is scaled automatically by Android
Example:
<Button
android:layout_width="120dp"
android:layout_height="48dp"/>
dp px
Density-independent Device-dependent
Recommended for UI Not recommended for UI
Scales across screens Fixed size
EditText is used for user input, while Button is used to trigger actions in an
Android user interface.
Examples
TextView
CheckBox
RadioButton
Spinner
7. What is a Fragment?
Key Points
Example
Introduction
Definition
A Broadcast Receiver can be used to detect when an SMS is received on the device
and perform an action such as displaying a notification or reading the message
content.
Advantages
Introduction
[Link] is a mandatory and essential configuration file in every
Android application. It provides the Android system with important information
about the app before it can run.
Definition
[Link] is a file that declares the structure, components, permissions,
and requirements of an Android application.
Simple Example
<manifest package="[Link]">
<uses-permission android:name="[Link]"/>
<application
android:label="MyApp"
android:icon="@mipmap/ic_launcher">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="[Link]"/>
<category android:name="[Link]"/>
</intent-filter>
</activity>
</application>
</manifest>
Importance of [Link]
The Android file system is divided into different directories, each having a
specific purpose. One of the most important directories is /system, which
contains the core files required for the Android operating system to function.
Definition
/system is a read-only directory in the Android file system that stores Android
OS system files, core libraries, and default applications.
Importance of /system
Critical for Android stability
Protects core OS components
Ensures secure and reliable operatio
Definitions
dp (Density-independent Pixel):
A unit used to define the size of UI elements such as buttons, layouts, and
margins. It scales according to screen density.
sp (Scale-independent Pixel):
A unit mainly used for text size. It scales according to screen density and
user’s font size preference.
Examples:
Definition
Explicit Intent:
An intent that directly specifies the target component (Activity or Service) to
be started.
Implicit Intent:
An intent that does not specify the target component. Instead, it declares an
action, and Android system decides which app/component can handle it.
Key Differences
Explicit Intent Implicit Intent
Target component is clearly
Target component is not specified
specified
Used mainly within the same Used to interact between different
application applications
More secure Less secure
No intent filter required Requires intent filters
Developer controls which System chooses the appropriate
component is launched component
Faster execution Slightly slower
Examples
Explicit Intent Example:
Intent intent = new Intent([Link], [Link]);
startActivity(intent);
✔ Used to move from one activity to another within the same app
Implicit Intent Example:
Intent intent = new Intent(Intent.ACTION_VIEW);
[Link]([Link]("[Link]
startActivity(intent);
✔ Used to open a webpage using any suitable app.
Use Cases
Explicit Intent
o Login → Home Activity
o Splash Screen → Main Screen
Implicit Intent
o Opening a browser
o Sending an email
o Making a phone call
o Sharing content
[Link] a short note on Linear Layout with one practical use case.
LinearLayout is one of the most commonly used layout containers in Android.
It arranges its child views in a single direction, either vertically or horizontally.
Definition
LinearLayout is a ViewGroup that places all its child views in one straight line,
either row-wise (horizontal) or column-wise (vertical).
Key Features
Supports vertical and horizontal orientation
Uses android:orientation attribute
Supports layout_weight to distribute space
Simple and easy to use
Example
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:text="Username"/>
<EditText
android:hint="Enter username"/>
<Button
android:text="Login"/>
</LinearLayout>
Definition
Sandboxing in Android is the process of running each application in its own
isolated environment to prevent unauthorized access to data and system
resources.
Advantages of Sandboxing
Protects user data
Prevents malicious access
Enhances system stability and security
Allows apps to run independently without interference
Practical Example
App A cannot read App B’s private files without permission.
A game app cannot access your contacts or SMS unless you explicitly grant
access.
[Link] the complete Activity Lifecycle with a neat labeled diagram and
describe the role of callback method.
An Activity in Android represents a single screen with a user interface. The Activity
Lifecycle describes the sequence of states an Activity goes through from creation to
destruction. Understanding this lifecycle is crucial to manage resources, save data, and
ensure smooth user interaction.
1. Activity
Definition: An Activity is a single screen with a user interface where users
interact with the app.
Purpose: Provides a UI for user interaction.
Example:
o Login screen, Home screen, Profile screen
Code Example:
Intent intent = new Intent([Link], [Link]);
startActivity(intent);
2. Service
Definition: A Service is a component that runs in the background without
user interaction.
Purpose: Performs long-running tasks such as music playback or
downloading files.
Example:
o Music player app playing songs in the background
Code Example:
Intent intent = new Intent(this, [Link]);
startService(intent);
3. Broadcast Receiver
Definition: A Broadcast Receiver listens for system-wide or app-wide
events.
Purpose: Reacts to broadcast messages even when the app is not running.
Example:
o Detecting incoming SMS, battery low alert
Code Example:
public class SmsReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// Handle incoming SMS
}
}
4. Content Provider
Definition: A Content Provider manages shared data between apps.
Purpose: Allows apps to read and write data in a structured way.
Example:
o Contacts app exposes contact information via a content provider
Code Example:
Cursor cursor = getContentResolver().query(
[Link].CONTENT_URI, null, null, null, null);
5. Intent Communication
Definition: An Intent is a messaging object used to request actions from
other components.
Types:
o Explicit Intent: Specifies the target component
o Implicit Intent: Specifies the action; the system chooses the
component
Example:
// Explicit Intent
Intent intent = new Intent([Link], [Link]);
startActivity(intent);
// Implicit Intent
Intent intent = new Intent(Intent.ACTION_VIEW);
[Link]([Link]("[Link]
startActivity(intent);
[Link] the role of Styles and Themes in Android. Why are they used?
In Android, Styles and Themes are used to define the appearance of UI
elements in a consistent way. They help developers maintain a uniform look
and feel across the application, reducing repetitive code.
1. Styles in Android
Definition:
A Style is a collection of attributes (like text size, color, padding, font)
applied to a single View or widget.
Purpose:
o Reuse common appearance settings
o Reduce redundancy in UI design
Example of Style:
<!-- res/values/[Link] -->
<style name="MyButtonStyle">
<item name="android:background">#FF5722</item>
<item name="android:textColor">#FFFFFF</item>
<item name="android:padding">10dp</item>
</style>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Click Me"
style="@style/MyButtonStyle"/>
2. Themes in Android
Definition:
A Theme is a style applied to an entire Activity or application, affecting
all UI elements within it.
Purpose:
o Maintain consistent look and feel across the app
o Easily change app-wide colors, fonts, and styles
Example of Theme:
<!-- res/values/[Link] -->
<style name="AppTheme"
parent="[Link]">
<item name="colorPrimary">#3F51B5</item>
<item name="colorPrimaryDark">#303F9F</item>
<item name="colorAccent">#FF4081</item>
</style>
<!-- In [Link] -->
<application
android:theme="@style/AppTheme"
... >
</application>
[Link] all tiers of Android system Architecture with a block diagram and
the functioning of each tier.
Android is built on a layered architecture consisting of several tiers. Each tier provides
specific functionalities and interacts with the layers above and below it. Understanding this
architecture helps developers know how apps, system services, and hardware interact in
Android.
Block Diagram of Android Architecture
1. Applications Layer
Description:
o Topmost layer visible to the user.
o Includes all pre-installed and user-installed apps like Phone,
Contacts, Gmail, Games, etc.
Function:
o Provides user interface and app-level functionality.
Example:
o WhatsApp, Google Maps, Camera
Definition
A Content Provider is a component that manages access to a central
repository of data. It allows one application to share data with other
applications in a controlled manner.
if (cursor != null) {
while ([Link]()) {
String name = [Link]([Link](
[Link].DISPLAY_NAME));
[Link]("Contact Name: " + name);
}
[Link]();
}
Explanation:
o [Link].CONTENT_URI is the URI of the
Contacts Content Provider.
o getContentResolver().query() allows your app to read contacts
securely.
The Android file system is divided into several partitions, each serving a
specific purpose for the operating system and applications. Among them, the
/boot and /cache partitions play critical roles in device startup and temporary
storage.
1. /boot Partition
Definition:
The /boot partition contains the kernel and the initial RAM disk
(initrd/initramfs) required to start the Android operating system.
Function / Purpose:
1. Kernel Storage: Stores the Linux kernel that controls hardware and
system processes.
2. Initial RAM Disk (initrd): Provides the essential files and drivers
needed to boot the system.
3. System Startup: Enables the device to load the operating system
during boot.
4. Recovery: Sometimes contains a small recovery environment for
troubleshooting.
Example / Usage:
o When you power on the device, the bootloader loads the kernel and
initrd from /boot to start Android.
2. /cache Partition
Definition:
The /cache partition is used to store temporary data generated by the system
and apps, which helps in improving device performance.
Function / Purpose:
1. Temporary Storage: Holds system cache files, app updates, and
downloaded data for quick access.
2. Faster App Launch: Speeds up app loading by caching frequently
used data.
3. OTA Updates: Used to temporarily store files during Over-The-Air
(OTA) system updates.
4. Clearing Cache: Can be cleared without affecting user data, often
done to fix minor device issues.
Example / Usage:
o When you install an app from Play Store, some temporary files are
stored in /cache for faster installation and execution.
o During an OTA update, the update file is temporarily stored in /cache
before being applied to /system.
Comparison Table
Partition Function Example / Use Case
Stores kernel and initial RAM disk Power-on device, kernel
/boot
for booting loading
Faster app launch, OTA
/cache Stores temporary system/app data
updates
1. App Sandboxing
o Each app runs in a separate environment with a unique UID.
o Apps cannot access other apps’ data without permission.
2. Permission Model
o Apps must request permissions to access sensitive resources:
camera, location, contacts, storage.
o User approval is required for sensitive operations.
3. Secure Inter-Process Communication (IPC)
o Apps communicate through Intents or Content Providers under
controlled permissions.
4. Verified Boot & System Integrity
o Android ensures that the system boots securely and prevents
tampering.
5. Encryption & Data Protection
o Android provides file-based encryption for user data.
o Data stored on the device is encrypted by default.
6. Regular Security Updates
o Security patches are applied via OTA updates to fix vulnerabilities.