activity-life cycle

Source: Internet
Author: User

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

Related Article

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.