Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activity Life Cycle

I'm trying to understand An Activity full life-cycle.

So I have searched on Google and found lots of tutorials regarding activity life-cycle, but in all tutorials I have not found these methods in life-cycle diagram:
1. OnContentChanged()
2. OnPostCreate()
3. OnPostResume()
4. OnWindowfocusChanged()
5. OnuserLeaveHint()
6. OnUserInteraction()
7. OnDetachedFromWindow()

I would like to known why these method's are not included in activity life-cycle diagram on android docs.

One more question:
When an activity is created for the fist time then system calls the OnContentChanged() method as the first method and last call by system is the OnDetachedFromWindow() method when an activity is killed, but android docs says entire lifetime of an Activity happens between OnCreate() and OnDestroy()?

like image 867
ρяσѕρєя K Avatar asked Mar 03 '12 15:03

ρяσѕρєя K


People also ask

What is activity life cycle?

Activity Lifecycle: Activity is one of the building blocks of Android OS. In simple words Activity is a screen that user interact with. Every Activity in android has lifecycle like created, started, resumed, paused, stopped or destroyed. These different states are known as Activity Lifecycle.

Why activity life cycle is important?

The Activity lifecycle is especially important because whenever an activity leaves the screen, the activity can be destroyed. When an activity is destroyed, when the user returns to the activity, the activity will be re-created and the lifecycle methods will be called again.

What are the 4 states of an activity?

Hence, all in all there are four states of an Activity(App) in Android namely, Active , Paused , Stopped and Destroyed .

What is activity lifecycle What is the significant role of each state?

The activity lifecycle is the set of states an activity can be in during its entire lifetime, from the time it's created to when it's destroyed and the system reclaims its resources. As the user interacts with your app and other apps on the device, activities move into different states.


1 Answers

Check out the Documentation for Activity All of these are in there, and many of them contain more detail than what I've listed here.

  1. This hook is called whenever the content view of the screen changes (due to a call to Window.setContentView or Window.addContentView).
  2. Called when activity start-up is complete (after onStart() and onRestoreInstanceState(Bundle) have been called).
  3. Called when activity resume is complete (after onResume() has been called).
  4. This hook is called whenever the window focus changes.
  5. Called as part of the activity lifecycle when an activity is about to go into the background as the result of user choice. For example, when the user presses the Home key, onUserLeaveHint() will be called, but when an incoming phone call causes the in-call Activity to be automatically brought to the foreground, onUserLeaveHint() will not be called on the activity being interrupted. In cases when it is invoked, this method is called right before the activity's onPause() callback. This callback and onUserInteraction() are intended to help activities manage status bar notifications intelligently; specifically, for helping activities determine the proper time to cancel a notfication.
  6. Called whenever a key, touch, or trackball event is dispatched to the activity.
  7. Called when the window has been detached from the window manager.
like image 110
FoamyGuy Avatar answered Nov 10 '22 01:11

FoamyGuy