Life cycle of activity in Android

Source: Internet
Author: User

1  Public classMainactivityextendsActivity {2 3 @Override4     protected voidonCreate (Bundle savedinstancestate) {5         Super. OnCreate (savedinstancestate);6 Setcontentview (r.layout.activity_main);7System.out.println ("OnCreate ()");8     }9 Ten @Override One     protected voidOnStart () { A         Super. OnStart (); -System.out.println ("OnStart ()"); -     } the  - @Override -     protected voidOnresume () { -         Super. Onresume (); +System.out.println ("Onresume ()"); -     } +  A @Override at     protected voidOnPause () { -         Super. OnPause (); -System.out.println ("OnPause ()"); -     } -  - @Override in     protected voidOnStop () { -         Super. OnStop (); toSystem.out.println ("OnStop ()"); +     } -  the @Override *     protected voidOnDestroy () { $         Super. OnDestroy ();Panax NotoginsengSystem.out.println ("OnDestroy ()"); -     } the  + @Override A     protected voidOnrestart () { the         Super. Onrestart (); +System.out.println ("Onrestart ()"); -}

Rewrite the above methods in Android Studio's Mainactivity.java to learn about the life cycle of activity in Android.

Running the project first displays the following results:

Then look at the results shown by the Logcat tool: OnCreate (), OnStart (), Onresume () life cycle has reached activity is running

Then press the home button to run as follows:

Activity executes to OnPause (), OnStop () is not cleared for this process, and then clicking on the once running program shows the following:

The activity goes through the right side of Onrestart (), OnStart (), Onresume () again into the activity is running, when clicking the Back button shows the following:

Activity is killed by OnPause (), OnStop (), OnDestroy (), and the life cycle of the activity ends.

Life cycle of activity in Android

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.