Android application components

Android application components are the essential building blocks of an Android app. Each component is a different point through which the system can enter your app.

There are four different types of android application components. Each type of android app component serves a distinct purpose and has a distinct lifecycle that defines how the component is created and destroyed.

  • Activities: An activity represents a single screen with a user interface.

    An activity is implemented as a subclass of Activity.

  • Services: A service is a component that runs in the background to perform long-running operations or to perform work for remote processes. A service does not provide a user interface. For example, a service might play music in the background while the user is in a different app, or it might fetch data over the network without blocking user interaction with an activity.

    A service is implemented as a subclass of

  • Content providers: A content provider manages a shared set of app data. Through the content provider, other apps can query or even modify the data (if the content provider allows it). For example, the Android system provides a content provider that manages the user's contact information. As such, any app with the proper permissions can query part of the content provider (such as ContactsContract.Data) to read and write information about a particular person.

    A content provider is implemented as a subclass of ContentProvider

  • Broadcast receivers: A broadcast receiver is a component that responds to system-wide broadcast announcements. Many broadcasts originate from the system—for example, a broadcast announcing that the screen has turned off, the battery is low, or a picture was captured. Apps can also initiate broadcasts—for example, to let other apps know that some data has been downloaded to the device and is available for them to use.

    A broadcast receiver is implemented as a subclass of BroadcastReceiver

Android application component activation

An Intent is an abstract description of an operation to be performed. Intent object, defines a message to activate either a specific component or a specific type of component. Intent if define a message to activate a specific component then it is called Explicit Intent. When Intent define a message to activate a specific type of component then it is called Implicit Intent.

There are separate methods for activating each type of component:

  • To start an Activity (or give it something new to do) we pass an Intent to startActivity() or startActivityForResult() (when we want the activity to return a result).
  • To start a Service (or give new instructions to an ongoing service) we pass an Intent to startService(). Or you can bind to the service by passing an Intent to bindService().
  • To initiate a Broadcast we pass an Intent to methods like sendBroadcast(), sendOrderedBroadcast(), or sendStickyBroadcast().
  • To perform an operation on a Content Provider we call specific method of ContentResolver.

As you can see 3 of 4 android app components can be activated by passing an Intent but Content Provider is activated when a request method of Content Provider is called by Content Resolver.

Share & Like

Tutorial topics

About is for Java, J2ee, Html5 and android developers. All tutorials are well explained and are easy to understand. We have tested every tutorials on our developement environment before posting it in public domain.