Understanding Android App Components

Proggy Blast
Proggy Blast
Published in
4 min readDec 4, 2020

It is the essential building block of android app. Each component is the entry point of the system or user can enter into the app. There are 4 components.

  1. Activity
  2. Services
  3. Broadcast Receivers
  4. Content Providers

Activity :

Activity is the entry point which the user can interact with the app. It represents the single screen with a user interface. An app can contain more than one activity and these activities has it’s own user interface.

We can reuse the same user interface with different activity. We can create our own activity by extending AppCompatActivity class.

Each activity has it’s own lifecycle. The lifecycle of android activity is mentioned below.

Activity Lifecycle — Proggy Blast

Services :

A service is a general purpose entry point for running an app into the background. It’s a component that runs in the background long running processes or to work for remote processes. A service doesn’t provide user interface.

Examples of services :

1. Playing music in the background and switching between different apps.

2. Making some network request without blocking the UI in an activity.

Another component, such as an activity can start the service and run / bind to it in order to interact with it.

Types of services :

1. Foreground services ( Music Player app)

2. Background services ( Runs in the background, where the system manages the process). Another component, such as an activity can start the service and run/bind to it in order to interact with it.

Foreground Services :

While using the foreground services the user has aware about the service is running in the background and it must show the running status to the user. Like the music player app plays the song even if we left the app and it plays the song. It don’t have the independent to kill the service periodically, it makes the user getting irritated.

Background Services :

On the other hand we have background services which we no need to show all our background operation details to the user. Like the network fetch data periodically and save it into database operation which handles completely in background. Here the system manages the service and it can kill the service and restart again based on memory requirement.

Services Lifecycle — Proggy Blast

We will check about the services in detail on the later articles.

Broadcast Receivers

Broadcast receiver is the another component that enables the system to deliever the events to the app outside of a regular user flow. It’s allowing the app to respond to system wise broadcast announcements.

The broadcast receiver is the well defined entry point into the app, the system can deliver broadcasts even to the apps that aren’t currently running.

For example, while the user app is getting the notification about the upcoming event, and delivering that alarm to a broadcast receiver of the app, until the app no need to remain run in the background until alarm goes off.

Many broadcasts are originated from the system. Some of them are,

1. Low Battery

2. Receiving Call

3. Screen turn off

4. Picture capture.

Apps also can initiate the broadcast from their app by creating the class with extend of BroadcastReceiver. Each broadcast delivered as intent object. It’s a just gateway to other components and intended to do very minimal amount of work.

Content Providers

Content providers are the shared set of data where you can store in the file system, SQLite database, on a web or any other persistant location that your app can access. Any apps with proper permissions can query and retireve the data from other apps.

For example contacts app is providing the contacts data with proper permissions.

Every app is identified by it’s own URI scheme. Your app can map based on these URI scheme. The URI’s data can be accessed of the when the owning app is still running.

Even for the clipboard action of one app where it can create the clipboard operation but restricting to the paritcular app and it locked it’s URI when exit from app. When the second app trying to access the clipboard part, it create the temporary URI and provide access for it.

Content Provider in android — Proggy Blast

--

--