Getting to Know Android App Structures: Activities, Fragments, and Broadcast Receivers

Examples of Content Provider Usage

1. Contact Application:

  • Content Provider allows other apps to access the user’s contact list.
  • Example: A messaging app uses a Content Provider to select the recipient’s contact.

2. Photo Gallery App:

  • Content Provider allows other apps to access photos and videos stored on the device.
  • Example: A social media app uses a Content Provider to select photos to upload.

3. Calendar App:

  • Content Provider allows other apps to access schedules and events on the user’s calendar.
  • Example: A reminder app uses a Content Provider to add events to the calendar.

7. Application Manifest: Glue That Holds Applications Together

Application Manifest is an XML file that serves as a “glue” that holds all the components of an Android app together. This file defines the structure of the application, including Activity, Service, Broadcast Receiver, and Content Provider, as well as the permissions required by the application.

The Important Role of Application Manifest

1. Defining Application Components:

  • Activity: Defines the screen or user interface.
  • Service: Define the background process.
  • Broadcast Receiver: Defines the components that respond to system messages.
  • Content Provider: Define the mechanism of data sharing.

Example of Activity definition  in AndroidManifest.xml:

<activity android:name=“.MainActivity”>
    <intent-filter>
      <action android:name=“android.intent.action.MAIN” />
   <category android:name=“android.intent.category.LAUNCHER” />
   </intent-filter>
</activity>

2. Declare Permission:

  • Android apps require permission to access certain features, such as camera, location, or the internet.
  • This permit was declared in AndroidManifest.xml.

Example of a permission declaration:

<uses-permission android:name=“android.permission.CAMERA” />
<uses-permission android:name=“android.permission.INTERNET” />

3. Defining Application Metadata:

  • Application Manifest also contains information such as app name, icon, theme, and version.

Example of app metadata:

<application
    android:name=“.MyApplication”
     android:icon=“mipmap/ic_launcher”
     android:label=“string/app_name”
      android:theme=“style/AppTheme”>
</application>

8. Application Resources: Assets for User Interface

The Android app stores resources such as strings, images, fonts, and UI layouts in the /res directory. These resources are managed separately from the program code, allowing you to easily customize the app for different devices, languages, and screen orientations.

Types of Resources

1. String: Text used in the app, such as titles, messages, or labels.

Stored in res/values/strings.xml.

Example:

<string name=“app_name”>My App</string>
<string name=“welcome_message”>Welcome to My App!</string>

2. Images: Visual assets such as icons, background images, or illustrations.

Stored in res/drawable/ or res/mipmap/.

Examples: ic_launcher.png, background.jpg.

3. (Layout) Layout: An XML file that defines the structure of the user interface.

Stored in res/layout/.

Examples: activity_main.xml, fragment_detail.xml.

4. Color: The definition of the color used in the application.

Stored in res/values/colors.xml.

Example:

<color name=“primary_color”>6200EE</color>
<color name=“secondary_color”>03DAC6</color>

5. Dimensions: The size and padding used in the layout.

Stored in res/values/dimens.xml.

Example:

<dimen name=“padding_small”>8dp</dimen>
<dimen name=“text_size_large”>24sp</dimen>

Latest Articles