Topic: The Big Four and the App’s Blueprint.
Activity: The entry point for interacting with the user; represents a single screen.
Service: Performs long-running operations in the background (no UI).
Broadcast Receiver: Listens for system-wide announcements (e.g., battery low).
Content Provider: Manages and shares a structured set of app data with other apps.
AndroidManifest.xml):Purpose: Provides essential information to the Android build tools, the OS, and Google Play.
Role: Declares permissions, hardware features, and all app components.
Location: Strictly found in the root of the project source set (usually src/main/).
Notes: If a component (like a Service) isn’t in the Manifest, the OS cannot “see” or start it. <receiver> is the tag for Broadcast Receivers.
This file found at the root of its source set.
This essential XML file serves as a “blueprint” or “passport” for the application
providing critical metadata for the following entities:
| Tag | Component | Purpose |
|---|---|---|
| activity | Activity: | Represents a single screen with a user interface. |
| receiver | Broadcast Receiver: | Allows the app to receive intents broadcast by the system or other apps. |
| provider | Content Provider: | Manages access to a structured set of data shared between apps. |
Element - Purpose
How apps talk to each other and the system.
An abstract description of an action to be performed.
Explicit Intent: Specifies the exact class name (e.g., “Start SettingsActivity.class”).
Implicit Intent: Specifies a general action (e.g., “Open a web page”); the system finds a matching app via Intent Filters.
Taking a Picture: Use ACTION_IMAGE_CAPTURE.
GPS/Location: Requires declaring <uses-permission> for FINE_LOCATION in the Manifest.
Music/Timers: Often involves specific actions like ACTION_SET_TIMER.
Notes: The Disambiguation Dialog (App Chooser). If multiple apps can handle an implicit intent, the system asks the user which one to use.
Managing state transitions.
Visible but no focus: onPause() is called (e.g., a dialog covers the screen).
No longer visible: onStop() is called; the activity is now a candidate to be killed if memory is low.
Returning to app: onRestart() → onStart() → onResume().
Transient State: Use onSaveInstanceState() to save “rememorable variables” (like a score) during screen rotations.
Modular UI sections that live inside an Activity; allow for flexible layouts across different screen sizes.
** Notes:** onStop() is the critical point where the activity “exists in memory” but is hidden. If it’s killed while stopped, it must be recreated via onCreate().
Declarative vs. Imperative design.
Imperative: Manually mutating views (e.g., textView.setText("...")).
Declarative (Compose): Describing what the UI should look like for a given state.
Modifiers: Used in declarative UI to decorate or augment composables (padding, size, etc.) works from outside to inside.
Toast: A small, transient pop-up message for brief feedback.
Role: Separation of logic from content (localization/themes).
res/raw: For arbitrary files like audio/video in their original format.
Notes: The strings.xml is a good example: it’s easier to translate an app into Spanish if the text isn’t hardcoded in the logic.
Storing data permanently.
Internal: Private, app-specific files.
External: Large, shareable files (photos, downloads).
Best Use: Large amounts of structured data.
Queries: Provides a full relational database engine for complex SQL querying.
Notes: SQLite is for complexity, while SharedPreferences is for simplicity.
From code to APK.
Version Control: Module-level build.gradle defines specific library versions.
Build Pipeline:
Compiling: Translates source code into DEX bytecode.
Linking: Combines compiled code with library dependencies.
Packaging: Bundles everything into an .apk or .aab file.
Deployment: Pushing the final package to a device or emulator.
Notes: “Linking” is where references between your code and external libraries (like Retrofit) are resolved so they function as one unit.