Type of Android Component
Previous Home Next

There are four different types of components in Android Application

  1. Activities
  2. Services
  3. Broadcast Receivers
  4. Content Providers
  • Activity : An Activity component provides a screen with which users can interact in order to do something, such as dial the phone, take a photo, send an email, or add contact detail.Of the four Android component, the only Activity must use at least in every application. Typically, one activity in an application is specified as the "main" activity, which is presented to the user when launching the application for the first time.
  • Each activity can then start another activity in order to perform different actions. Each time a new activity starts, the previous activity is stopped,

    Each individual screen within an Android application is an activity, and users can perform actions by interacting with the visual components within an activity.

    An application usually consists of multiple activities and each activity operates independently of one another

    The visual objects within an activity (blocks of text, input boxes, buttons, etc.) are usually organized and instantiated by implementing instructions within a layout XML file.

    Each activity in an Android application is either a direct subclass of the Activity base class or a subclass of an Activity subclass that provides specialized functionality (such as the ListActivity class which contains methods specifically for the display of data in a touch-enabled list), and is represented in the application package as a single Java class.

    All Android application components, including activities, have lifecycles.All activities inherit a set of lifecycle methods from the Activity base class that are executed when the corresponding lifecycle state of the activity is reached.

    These lifecycle methods are

    1. onCreate : This method is called when the activity is first instantiated/loaded into memory. This is the method in which you want to set up the intial state of your variables, instantiate the visual objects within the activity via your layout file, and bind your event listeners.
    2. onRestart: called when the activity is being restarted (made visible again) after executing onStop but not onDestroy.
    3. onResume: this method called just before the activity starts interacting with the user. After the onResume() method is called, the activity is considered to be "running."
    4. onPause: This method is called when the system is about to start resuming another activity.This method is followed either by onResume() if the activity returns back to the front, or by onStop() if it becomes invisible to the user.
    5. onStop: This method is called when the activity is no longer visible to the user. This method is followed either by onRestart() if the activity is coming back to interact with the user, or by onDestroy() .
    6. onDestroy: This method is called just before an activity is destroyed/unloaded from memory.
    7. onStart : This method is called just before the activity becomes visible to the user.
    Previous Home Next