Android life cycle (iii)

Source: Internet
Author: User

The life cycle of an Android application is more clear than the explanation.



Create a demo with the following code:

public class Mainactivity extends Activity {private static final String TAG = "Android_life"; @Overrideprotected void Oncre Ate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); LOG.I (TAG, "onctreate ()"); Setcontentview (R.layout.activity_main);} protected void OnStart () {Super.onstart (); LOG.I (TAG, "OnStart ()");} protected void Onresume () {super.onresume (); LOG.I (TAG, "Onresume ()");} protected void OnPause () {super.onpause (); LOG.I (TAG, "OnPause ()");} protected void OnDestroy () {Super.ondestroy (); LOG.I (TAG, "OnDestroy ()");}

The effect of running the program is as follows:

1) The first time you run the program, you can find the log information as follows: "Note time"

03-10 20:38:11.531:i/android_life (4635): Onctreate ()
03-10 20:38:11.641:i/android_life (4635): OnStart ()
03-10 20:38:11.641:i/android_life (4635): Onresume ()

2) Turn off the phone screen

03-10 20:38:11.531:i/android_life (4635): Onctreate ()
03-10 20:38:11.641:i/android_life (4635): OnStart ()
03-10 20:38:11.641:i/android_life (4635): Onresume ()
03-10 20:38:29.451:i/android_life (4635): OnPause ()

3) Activate the phone screen

03-10 20:38:11.531:i/android_life (4635): Onctreate ()
03-10 20:38:11.641:i/android_life (4635): OnStart ()
03-10 20:38:11.641:i/android_life (4635): Onresume ()
03-10 20:38:29.451:i/android_life (4635): OnPause ()
03-10 20:53:51.631:i/android_life (4635): OnStart ()
03-10 20:53:51.731:i/android_life (4635): Onresume ()

4) exit the application and you can see the log

03-10 20:57:51.161:i/android_life (5779): OnDestroy ()

Android life cycle (iii)

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.