Android App Components
📌App Components
App components are fundamental building blocks of an Android app, each providing an entry point for the system or user. These components, loosely coupled by the manifest file (AndroidManifest.xml
), include:
Activities
Services
Broadcast Receivers
Content Providers
📍Activities
The entry point for user interaction represents a single screen with a UI (user interface).
Every activity is a single-screen
public class MainActivity extends Activity { }
📍Services
Background component for long-running operations, running independently of UI.
Can play music, fetch data, etc., while allowing other components to interact.
Two Types: Started services (for background tasks) and Bound services (provides API for other processes).
public class MyService extends Service { }
📍Broadcast Receivers
Handle Communications between Android OS and Applications.
Responds to broadcast messages from other apps or the system.
Handles system-wide events, even when the app is not running.
Example: Handling alarms to post notifications.
public class MyReceiver extends BroadcastReceiver { public void onReceive(Context context, Intent intent) {} }
📍Content Providers
Manages shared app data accessible by other apps (e.g., contacts).
Provides a standardized method for data sharing.
Implemented as a subclass of
ContentProvider
.public class MyContentProvider extends ContentProvider { public void onCreate() {} }
📌Additional Components
Fragments:
Represents a portion of the user interface within an Activity.
Views:
UI elements like buttons, lists, and forms.
Layouts:
View hierarchies controlling screen format and appearance.
Intents:
Messages facilitate communication between components.
Resources:
External elements (strings, constants, images).
Manifest:
Configuration file for the application.
Last updated