Android LifeCycle notes
Android LifeCycle notes
1. Activities
Definition:
An Activity represents a single screen with a user interface (UI). It acts as the entry point for
user interactions with your app. Activities are critical for designing and managing the UI
and handling user interactions.
Key Features:
• Each activity is independent but can communicate with other activities using
Intents.
• They are part of the back stack, which maintains the order of activities.
Lifecycle:
1. onCreate(): Called when the activity is first created. Use this to initialize UI
components.
2. onStart(): Called when the activity becomes visible to the user.
3. onResume(): Called when the activity is ready for the user to interact with.
4. onPause(): Called when the activity is partially obscured (e.g., another activity
appears as a dialog).
5. onStop(): Called when the activity is no longer visible.
6. onDestroy(): Called before the activity is destroyed and removed from memory.
Example:
Definition:
Types of Services:
Lifecycle Methods:
Example:
3. Content Providers
Definition:
Content Providers manage access to a structured set of data. They allow different
applications to share data securely and efficiently.
Key Methods:
Use Cases:
Example:
• Contacts: ContactsContract.Contacts.CONTENT_URI
• Media: MediaStore.Images.Media.EXTERNAL_CONTENT_URI
4. Broadcast Receivers
Definition:
A Broadcast Receiver is a component that listens for and responds to broadcast messages
from the system or other applications.
Use Cases:
• Responding to system events such as battery level changes, Wi-Fi status, or device
boot.
• Implementing custom application-level events.
Types:
Key Method:
Example:
• Static Registration:
<receiver android:name=".MyBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
• Dynamic Registration:
Summary