Android activity lifecycle


     Android activity goes through series of states when user navigates through an application. As explained earlier Android applications do not control their own process lifetimes. Although the run time handles the termination and management of an Activity's process, the Activity's states helps determine the priority of its parent application.
The applications priority in turn influences the likelihood that the run time will terminate it and the Activities running within it.

Activity Stack
       Activity stack is a last-in-first-out collection of all currently running activities. For each application that is running on an Android device, the runtime system maintains an Activity Stack. The state of each Activity is determined by its position on the Activity stack. When a new Activity starts, it becomes active and is moved to the top of the stack.
    If the user navigates back using the Back button the next activity down on the stack moves up and becomes active. In other words, when a second activity is started, it is placed on the top of the stack and the previous activity is pushed down.
      An applications priority is influenced by its highest-priority Activity. Activity stack is used when it comes to place which application has to be terminated to free resources. 

Activity States
       As activities are created and destroyed they move in and out of the stack. As they do, they transition through four possible states: 

Active State
  •         Activity that is receiving user input
  •         It is at the top of the stack, visible, focused, foreground
  •         This active activity is kept alive in all circumstances by killing activities down the stack.
  •         When another activity becomes active, this activity will be paused.

Paused State
  •          Activity will be visible but will not have focus
  •          When paused activity is treated as if it were active, but will not receive any user input.
  •          Paused activities are held in memory and can retain all state information and can quickly be                  restored to active status

Stopped State          
  •           Activity will not be visible to the user.
  •           Activity will remain in memory retaining all state information.
  •           Before an activity enters stopped state, it is important to save data and the current UI state for             unplanned termination.

Inactive State
  •           After an activity is killed and before its launched, its inactive.
  •           Such activities are removed from activity stack. 
State transitions are handled by Android memory manager.

1 comment:
Write comments

Popular Posts

Find us on Facebook