Tuesday, July 5, 2016

Android Application Components

In this article we will talk about various components of which android application is made of.
NOTE: Manifest file (AndroidManifest.xml) contains information of each component of application and how they interact.
There are mainly four types of components that are used to build an application and we will use these components or class to create our application or May extends these classes as per our need.


  • Activity is a user interface screen where visual elements called Views (Widgets such TextView, EditText etc.) are present and can perform some action on getting users input.
  • Widgets or Views on an Activity can be created by two ways, by Java Code or by XML code, we will mostly used XML code.
Activity, Learn Android Application Development, 2TechUp
  • An android application can have any no. of Activity but out of these activities one activity must be declared as launcher activity.
  • Each Activity in Android is implemented as a subclass of Activity class
public class MainActivity extends Activity {


  • Service is an Android application component that runs in background and has no visual UI as Activity have.
  • These are used to perform the processing parts of Android application
  • A service can be started by other Android component such as Activity or by other Service also.
  • Example: Suppose you are watching a movie on your mobile and downloading games from Play Store (this task is performed in background). This can be made possible only by use of Android Services.
  • Each Service in Android is implemented as a subclass of Service class
public class MyService extends Service {

3.Broadcast Receivers

  • Broadcast Receivers are used to get messages that are broadcasted by Android System or other Android Application.
  • Example: Warning that battery is low, Screen turned off etc.
  • Each Broadcast Receiver in Android is implemented as a subclass of BroadcastReceiver class
public class MyReceiver  extends  BroadcastReceiver {
   public void onReceive(context,intent){}

4.Content Provider

  • Supplies data from one application to another on request
  • These data may be stored in file system, the database or somewhere else.
  • Each Content Provider in Android is implemented as a subclass of ContentProvider class
public class MyContentProvider extends  ContentProvider {
   public void onCreate(){}
We will go in details of these components in our next posts.

Additional Components

Fragments: Represent portion of UI in an Activity
Views: UI Elements or Widgets such TextView, EditText, Button etc
Layouts: Visual structure that can hold View
Intents: Component used to activate particular component
Resources: External elements such as Strings, Colors etc.
Manifest: Configuration file for the application.