No more nonsense, just look at the log print results.
The main use of this is two activity, one is file, one is sound
1. When the app is opened, go directly to the sound activity. Printing results are as follows
in-Geneva:36.5647810): sound_oncreate05 -Geneva:36.7007810): Sound_onstart05 -Geneva:36.7017810: Sound_onresume
That is, to enter an activity, the first thing is to execute Oncreate->onstart->onresume
2. When we lock the screen from this activity screen, print the log as follows
in-Geneva:11.3567810): Sound_onpause -Geneva:11.4997810: Sound_onstop
That is, Onpause->onstop was executed.
If we unlock it and get into this activity again,
7810:52.362 sound_onstart): -Geneva:52.3767810): Sound_onresume
Executed the Onstart->onresume
3. When we press the home button at the activity interface,
And when you re-enter.
to-Geneva to: on:32.301E/zhangshuli (7810): Sound_onpause to-Geneva to: on:33.098E/zhangshuli (7810): Sound_onstop to-Geneva to: on:38.816E/zhangshuli (7810): Sound_onstart to-Geneva to: on:38.816E/zhangshuli (7810): Sound_onresume
You can see that it performs the same as the lock screen.
4. Under the Activity screen, press the Back button
7810:59.148 sound_onpause): -Geneva:59.7917810): Sound_onstop- Geneva :59.8017810): Sound_ondestory
It's a destory process more than any other case.
5. When we switch from the Sound->file interface
to-Geneva to:Geneva:34.316E/zhangshuli (7810): Sound_onpause to-Geneva to:Geneva:34.343E/zhangshuli (7810): File_oncreate to-Geneva to:Geneva:34.443E/zhangshuli (7810): File_onstart to-Geneva to:Geneva:34.444E/zhangshuli (7810): File_onresume to-Geneva to:Geneva:34.991E/zhangshuli (7810): Sound_onstop
It will be found that the activity execution OnPause is started first, then the activity execution Oncreate->onstart->onresume is initiated and the activity execution is initiated OnStop
6. When we press the back button
to-Geneva to: -:53.804E/zhangshuli (7810): File_onpause to-Geneva to: -:53.828E/zhangshuli (7810): Sound_onstart to-Geneva to: -:53.828E/zhangshuli (7810): Sound_onresume to-Geneva to: -:54.272E/zhangshuli (7810): File_onstop to-Geneva to: -:54.273E/zhangshuli (7810): File_ondestory
To do this, start activity onpause, then start activity execution Onstart->onresume, and finally start activity execution onstop->ondestory
7. In addition to the above life cycle, there is a status of Onsaveinstancestate and Onrestoreinstancestate
Log as follows
-Geneva:26.9278539): Sound_onpause -Geneva:27.6348539): Sound_onsave- Geneva :27.6558539: Sound_onstop
OnSave is executed after OnPause, Onrestore is executed after OnStart
As follows
to-Geneva .: -:18.764E/zhangshuli (8539): File_ondestory to-Geneva .: -:18.783E/zhangshuli (8539): File_oncreate to-Geneva .: -:18.857E/zhangshuli (8539): File_onstart to-Geneva .: -:18.858E/zhangshuli (8539): File_onrestore to-Geneva .: -:18.881E/zhangshuli (8539): File_onresume
activity-life cycle