Application components of android are very important for building applications. They work as an entry point for users or system to enter your application. There are four different types of components. Every component has its own purpose and distinct life cycle.
Following are the basic components that can be used in android application:
An android activity represents a single screen with a user interface (UI) and it will acts as an entry point for the user’s to interact with the app. Each activity is independent of each other.
For example, a messenger app that has multiple activities like sending the message, writing a new message. All these activities in the messaging app are independent of each other but will work together to provide a better user experience.
The android activity is implemented as a subclass of Activity class as follows:
In android, the service component keeps an app running in the background to perform long-running operations based on our requirements. It keeps updating data sources and activities and it will run the apps in the background like play music in the background when the user using a different app.
The service is implemented as a subclass of Service class as follows:
The content provider component allows applications to share data from one application to another on request. It hides the details of the database and can be used to read and write private data of the application which is not shared. It would be difficult to access data from other applications without content providers.
The content provider is implemented as a subclass of ContentProvider class as follows:
The broadcast receiver component responds to broadcast messages from another application or the same system. It can also deliver broadcasts to applications that are not running. For example, notify the user that the battery is low. The broadcast messages can be used in the application or outside the normal flow.
The broadcast receiver is implemented as a subclass of BroadcastReceiver class as follows:
Additional Components of Android Application:
Following are some additional components of an android application: