Activity Life Cycle in Android

What is Activity :

  • Activity is a single screen
  • Activity is a single, individual focused screen that’s comes in front to the user.
  • Activity doesn’t contain anything of its own.
  • It loads the layout that contain activity elements called views like Buttons, EditText, TextViews, Spinner, Checkboxes, RadioButtons etc.
  • Users can perform actions by interacting  with the visual components within an activity.


Four States of Activity:
  • Active/Running State
  • Paused State
  • Stopped State
  • Destroyed State


Activity Life Cycle:

Active/Running State:

State when the activity is in foreground or active or in focus to the user mobile device.

Paused State:

Activity is partially visible, or not in the focus somehow another activity has taken place. Activity in paused state does not cover the entire screen.

Stopped State:

Activity is no longer visible in the screen. Another activity is on top of it.

Destroyed State:

Dead or destroyed when it no longer exists in the memory.


Details Description:

onCreate()-
  • Whenever Activity launches, It calls the onCreate() method of Activity class.
  • Every class is treated as Activity when it extends Activit class of Android.
  • It must override the onCreate() method.
  • This method defines the UI or the layout the activity class loads.
  • It has Bundle object to store UI state.


onStart()-
  • This method is called before any activity is visible to the user.
  • This spot of time activity is still not active.

onResume()-
  • Activity is visible and interactive to the user.
  • It able to receive inputs.
  • It is on the top of the activity stack

onPause()-
  • Whenever another activity comes into the front original activity goes into partial background.
  • There is a possibility of being killed by the system at the activities paused state.
  • If the user has pressed paused button, notification comes in front, device in sleep mode in all these cases the activity is in paused state

onDestroy()-
  • Called when the activity is destroyed.
  • This is the last method which is being called before the activity is destroyed.
  • By this method system will able to release the activity from the memory and get some free space. 


                                 Reach us At: - 0120-4029000 / 24 / 25 / 27 / 29 Mbl: 9953584548
Write us at: - smruti@apextgi.com and pratap@apextgi.com


1 comment: