Life cycle Illustrations The following English citations are all from Google's official documentation for easy comprehension. OnCreate (Bundle savedinstancestate) can callfinish()From within this function, in which case OnDestroy () 'll be immediately called without any of the rest of the activity Li Fecycle (onStart(),onResume(),onPause(), etc) executing. If OnCreate inside the direct finish (), will not go the other way, will directly ondestory (). You can print your own log and try it, indeed. Onresume () called afteronRestoreInstanceState(Bundle),onRestart(), oronPause(), for your activity-to-start interacting with the user. This was a good place to begin animations, open exclusive-access devices (such as the camera), etc. It is possible to call after these three methods, which is an open animation or A good time to have a proprietary device (such as a camera). Keep in mind that Onresume are not the best indicator that your activity is visible to the user; A system window such as the Keyguard May is in front. UseonWindowFocusChanged(boolean)To know for certain this your activity is visible to the user (for example, to resume a game). But it does not mean that your acitivity is visible to the user, it is possible that the system window is still in front of you, such as the case of the lock screen, this acitivity has been onresume, but in fact is not visible. If you want to determine whether this avitivity is visible to the user, you can use the Onwindowfocuschanged (Boolean) method to determine it. It will run after the Onresume. Example: Acitvity into focus mainactivity onCreate
Mainactivity OnStart
Mainactivity Onresume
Mainactivity onwindowfocuschanged Hasfocus=true When this activity exits mainactivity onwindowfocuschanged hasFocus=false
Mainactivity OnPause
Mainactivity OnStop
Mainactivity OnDestroy OnPause ()
Called as part of the activity lifecycle if an activity was going into the background, but had not (yet) been killed.
When activity B was launched in front of activity A, this callback would be invoked on a. b won't be created until a ' s returns, so is sure to does anything lengthy here.
This method is triggered when activity is going into the background, but has not been killed yet. For example, when B is started on a, this method is triggered. Unless the OnPause method of a is executed, B will not create. So make sure you don't do too much in this method. This callback was mostly used for saving all persistent state the activity was editing, to present a "edit on place" Model T o the user and making sure nothing is lost if there be not enough resources to start the new activity without first Killi Ng this one. This is also a good place to does things like stop animations and other things that consume a noticeable amount of CPUs in or Der to do the switch to the next activity as fast as possible, or to close resources that is exclusive access such as T He camera. This method is mainly used to save some acitivity in the state of being edited or to turn off some animations to make the CPU work better so that the next activity can be opened more quickly (the UI always shows the user the essence of----life cycle design first), or close some resources, Like camera. After receiving the usually receive a following call toonStop()(after the next activity have been resumed and displayed), however in some cases there would be a direct call back toonResume()Without going through the stopped state. After this method call, OnStop is called, but waits until the next activity is shown.
OnStop () Called when you're no longer visible to the user. This method is called when it is completely invisible to the user. Note that this method may never is called, in low memory situations where the system does not has enough memory to keep y Our activity ' s process running after itsonPause()method is called. Note that this approach may not be called at all, when the memory is critically low when the activity OnPause (), there is not enough memory to execute OnStop (); (If you start that picture, go straight OnPause to the left) Additional considerations: From mainacitivity----Jump--->secondactivity log: mainacitivity onCreate () mainacitivity OnStart () Mainacitivity onresume () mainacitivity onPause () secondactivity onCreate ( ) secondactivity OnStart () secondactivity onresume () mainacitivity onStop ()
Android Life cycle Considerations