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:

  1. Activities

  2. Services

  3. Broadcast Receivers

  4. 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

  1. Fragments:

    • Represents a portion of the user interface within an Activity.

  2. Views:

    • UI elements like buttons, lists, and forms.

  3. Layouts:

    • View hierarchies controlling screen format and appearance.

  4. Intents:

    • Messages facilitate communication between components.

  5. Resources:

    • External elements (strings, constants, images).

  6. Manifest:

    • Configuration file for the application.


Last updated