Activity Life-Cycle method –
1.
onCreate(Bundle
savedInstanceState) : Called when the activity is starting.
2.
onStart() : Called after
onCreate(Bundle) — or after onRestart() when the activity had been stopped, but
is now again being displayed to the user.
3.
onResume() : Called after onRestoreInstanceState(Bundle),
onRestart(), or onPause(), for your activity to start interacting with the
user.
4.
onPause() : Called as part of the
activity lifecycle when an activity is going into the background, but has not
(yet) been killed.
5.
onStop() : Called when you are
no longer visible.
6.
onRestart() : Called after onStop()
when the current activity is being re-displayed to the user (the user has
navigated back to it).
7.
onDestroy() : Perform any final
cleanup before an activity is destroyed.
More Depth
Situations
1.
When
open the app
onCreate() --> onStart()
--> onResume()
2.
When
back button pressed and exit the app
onPaused() -- > onStop()
--> onDestory()
3. When home button pressed
onPaused() --> onStop()
4.
After
pressed home button when again open app from recent task list or clicked on
icon
onRestart() --> onStart()
--> onResume()
5.
When
open app another app from notification bar or open settings
onPaused() --> onStop()
6.
Back
button pressed from another app or settings then used can see our app
onRestart() --> onStart()
--> onResume()
7.
When
any dialog open on screen
onPause()
8.
After
dismiss the dialog or back button from dialog
onResume()
9.
Any
phone is ringing and user in the app
onPause() --> onResume()
10. When user pressed phone's answer button
onPause()
11. After call end
onResume()
12. When phone screen off
onPaused() --> onStop()
13. When screen is turned back on
onRestart() --> onStart()
--> onResume()
-----------------------------------------------------------------------
1. When first Activity open
In the First onCreate() event
In the First onStart() event
In the First onResume() event
2. When called First to Second Activity
In the First onPause() event
In the Second onCreate() event
In the Second onStart() event
In the Second onResume() event
In the First onStop() event
3. When called Second to First Activity
In the Second onPause() event
In the First onCreate() event
In the First onStart() event
In the First onResume() event
In the Second onStop() event
Note - 2, 3 are common
4. When pressed home button, app running in background
In the First onPause() event
In the First onStop() event
5. When removed from background
In the First onDestroy() event
First onStart() event
First onPostCreate() event
First onResume() event
First onPostResume() event
Case : First Activity - Second Activity
1. When first Activity open
In the First onCreate() event
In the First onStart() event
In the First onResume() event
2. When called First to Second Activity
In the First onPause() event
In the Second onCreate() event
In the Second onStart() event
In the Second onResume() event
In the First onStop() event
3. When called Second to First Activity
In the Second onPause() event
In the First onCreate() event
In the First onStart() event
In the First onResume() event
In the Second onStop() event
Note - 2, 3 are common
4. When pressed home button, app running in background
In the First onPause() event
In the First onStop() event
5. When removed from background
In the First onDestroy() event
Case 2 : When called all method
First onCreate() eventFirst onStart() event
First onPostCreate() event
First onResume() event
First onPostResume() event
Below Image for Deep understanding
No comments:
Post a Comment