The Android system adds hooks to the activity lifecycle, and we can do something with the hooks that are reserved for these systems.
Examples of 7 commonly used hooks are cited:
protected void OnCreate (Bundle savedinstancestate)
protected void OnStart ()
protected void Onresume ()
protected void OnPause ()
protected void OnStop ()
protected void Onrestart ()
protected void OnDestroy ()
Brief Description:
OnCreate (Bundle savedinstancestate): Called when an activity is created. The setting is http://www.myexception.cn/in the method, and the information needed to create the activity can be presented in bundle.
OnStart (): The activity becomes called when it is visible to the user on the screen, that is, when the focus is obtained.
Onresume (): The activity begins to be invoked when it interacts with the user (the method is always invoked, whether it is to start or restart a campaign).
OnPause (): The activity is called when the CPU and other resources are paused or retracted, which is used to save the active state.
OnStop (): Called when the activity is stopped and becomes invisible and subsequent life cycle events, that is, when the focus is lost.
Onrestart (): Called when the activity is restarted. The activity is still on the stack, java.io.UnsupportedEncodingException rather than starting a new activity.
OnDestroy (): Called when an activity is completely removed from system memory, the method may be invoked because someone calls the finish () method directly or the system decides to stop it to free resources.
switch at the same screen 1 Switch to horizontal screen Onsaveinstancestate
OnPause
OnStop
OnDestroy
OnCreate
OnStart
Onrestoreinstancestate
Onresume
2 Switch to the vertical screen, destroyed two times Onsaveinstancestate
OnPause
OnStop
Ondestroyoncreate
OnStart
Onrestoreinstancestate
Onresume
Onsaveinstancestate
OnPause
OnStop
OnDestroy
OnCreate
OnStart
Onrestoreinstancestate
Onresume
3 Modify Androidmanifest.xml, add the activity android:configchanges= "orientation", cut the horizontal screen, only destroy once Onsaveinstancestate
OnPause
OnStop
OnDestroy
OnCreate
OnStart
Onrestoreinstancestate
Onresume
4 and then cut back to the vertical screen, found that no longer print the same information, but print more than one line onconfigchanged Onsaveinstancestate
OnPause
OnStop
OnDestroy
OnCreate
OnStart
Onrestoreinstancestate
Onresume
Onconfigurationchanged
6 cut back to the vertical screen Onconfigurationchanged
Onconfigurationchanged
Summary:
1, do not set the activity of the android:configchanges, the screen will recall each life cycle, cut the horizontal screen will be executed once, cut the vertical screen will be executed twice
2, set the activity of the android:configchanges= "orientation", cut screen or will recall the life cycle, cut horizontal, vertical screen will only perform once
3, set the activity of the android:configchanges= "Orientation|keyboardhidden", the screen will not recall each life cycle, will only execute the Onconfigurationchanged method
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service