Learn the life cycle of android<activity from scratch. 39 .>

Source: Internet
Author: User


Intent refers to the transformation of the two UI main interface, which requires learning the life cycle of an activity to understand the intent

The default in the UI interface shows the run as running state, while the OnPause method in the background

Main:

OnCreate ()-OnStart ()-Onresume ()-->onpause ()-->onstop ()-->ondestroy ()

Sub-line:

OnCreate ()-OnStart ()-Onresume ()-->onpause ()-->onstop ()-->onrestart ()-->onstart () Onresume ()-->onpause ()-->onstop ()-->ondestroy ()


Now let's take a look at the activity's declaration cycle.

By default creating an Android project will default to you to create a OnCreate method


Let's write it down separately.

        protected void OnCreate (Bundle savedinstancestate);                protected void OnStart ();                   protected void Onrestart ();                protected void Onresume ();               protected void OnPause ();                protected void OnStop ();                protected void OnDestroy ();
Use an example to see its life cycle.


Package Com.example.activity;import Android.os.bundle;import Android.app.activity;import android.view.Menu;public Class Mainactivity extends Activity {@Override protected void onCreate (Bundle savedinstancestate) {Super.on        Create (savedinstancestate);        Setcontentview (R.layout.activity_main);    System.out.println ("onCreate-----Activity Establishment-----"); } @Overrideprotected void Onresume () {//TODO auto-generated method Stubsuper.onresume (); System.out.println ("onresume-----activity shows to the main UI-----");} @Overrideprotected void OnDestroy () {//TODO auto-generated method Stubsuper.ondestroy (); System.out.println ("OnDestroy-----activity destroyed, can no longer restart-----");} @Overrideprotected void OnPause () {//TODO auto-generated method Stubsuper.onpause (); System.out.println ("onPause-----activity suspended exiting to bottom-----");} @Overrideprotected void Onrestart () {//TODO auto-generated method Stubsuper.onrestart (); System.out.println ("onrestart-----activity into the restart queue----");} @Overrideprotected void OnStart () {//TODO AuTo-generated method Stubsuper.onstart (); System.out.println ("onStart-----Activity Restarts-----");} @Overrideprotected void OnStop () {//TODO auto-generated method Stubsuper.onstop ();    System.out.println ("onStop-----Activity Stop-----");} }
When you start a project


Press the main Menu key on the simulator



Click on the installed program to re-return the program



Press the exit key to exit the program





In fact, the UI display of different activity is a stack process that displays the activity at the top of the stack.

Next Forecast: Intent intent

Learn the life cycle of android<activity from scratch. 39 .>

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.