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:
Activities
Services
Content Providers
Broadcast Receivers
Activities:
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:
public class MainActivity extends Activity {
}
Services:
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:
public class MyService extends Service {
}
Content Providers:
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:
public class MyContentProvider extends ContentProvider {
public void onCreate(){}
}
Broadcast Receivers:
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:
public class MyReceiver extends BroadcastReceiver {
public void onReceive(context,intent){}
}
Additional Components of Android Application:
Following are some additional components of an android application:
Fragments: Fragments are used to represent the portion of the user interface in an activity.
Views: These are used to build a user interface for an app using UI elements like buttons, lists, etc.
Intents: It's an inter-application message passing framework for communication between android components.
Layouts: Layouts are used to define the user interface (UI) for an activity or app.
Resources: To build an android app we required external elements like images, audio files, etc. other than coding.
Manifest: It is a configuration file for the application and it contains the information about activities, intents, content providers, services, broadcast receivers, permissions, etc.
We use cookies to ensure that we give you the best experience on our website. If you continue to use this site we will assume that you are happy with it.Ok