Architecture of Mobile Applications
1. Definition and Importance
1.16. Example Code
Example Code
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Toast.makeText(context, "Broadcast Received!", Toast.LENGTH_SHORT).show();
}
}
Registering a Receiver in Manifest
<receiver android:name=".MyReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
Use Cases
- Detecting when the device boots up.
- Monitoring network changes.
- Handling push notifications.
These four core components—Activities, Fragments, Services, and Broadcast Receivers—are fundamental to Android app development. Each serves a distinct purpose:
- Activities manage UI interactions.
- Fragments offer reusable and flexible UI components.
- Services handle background tasks.
- Broadcast Receivers listen for and respond to system-wide events.