An Activity is usually a single screen that the users sees on the device at a one time. Any application that has been developed by anyone it typically contains multiple activities.
* Most management of the life cycle is done automatically by the system via the activity Stack .
* Activity manager is responsible for creating , destroying and managing activities.
In Activity Life Cycle we are having following methods:
1. onCreate() 2. onStart() 3. onRestart() 4. onResume() 5. onPause() 6. onStop() 7. onDestroy()
1.The activity first time loads the methods are called as below:
onCreate() onStart() onResume()
2.When try to click back button or finish the activity the following methods are called:
onPause() onStop() onDestroy()
3.When you click on home button the activity goes to background and below methods are called:
onPause() onStop()
4.After hitting home button again if your opening the previous activity which is in background the following methods are called:
onRestart() onStart() onResume().
Firsttime Launch:
com.example.activitylifecycle E/onStart ------: MainActivity: onStart()
com.example.activitylifecycle E/onResume ------: MainActivity: onResume()
Start AnotherActivity:
com.example.activitylifecycle E/onPause ------: MainActivity: onPause()
com.example.activitylifecycle E/onCreate ------: AnotherActivity: onCreate()
com.example.activitylifecycle E/onStart ------: AnotherActivity: onStart()
com.example.activitylifecycle E/onResume ------: AnotherActivity: onResume()
com.example.activitylifecycle E/onStop ------: MainActivity: onStop()
Press BackButton:
com.example.activitylifecycle E/onPause ------AnotherActivity: onPause()
com.example.activitylifecycle E/onRestart ------: MainActivity: onRestart()
com.example.activitylifecycle E/onStart ------: MainActivity: onStart()
com.example.activitylifecycle E/onResume ------:MainActivity: onResume()
com.example.activitylifecycle E/onStop ------: AnotherActivity: onStop()
com.example.activitylifecycle E/onDestroy ----AnotherActivity: onDestroy()
Complete back mainactivity:
activitylifecycle E/onPause ------: MainActivity: onPause()
com.example.activitylifecycle E/onStop ------: MainActivity: onStop()
com.example.activitylifecycle E/onDestroy ------:MainActivity: onDestroy()
Home Button:
E/onPause ------: MainActivity: onPause()
com.example.activitylifecycle E/onStop ------: MainActivity: onStop()
Home Button:
E/onPause ------: MainActivity: onPause()
com.example.activitylifecycle E/onStop ------: MainActivity: onStop()
Very nice
ReplyDelete