Android page switching and execution order of common methods

Source: Internet
Author: User

Package com.example.android.active;import android.os.bundle;import android.app.activity;import  android.content.intent;import android.view.menu;import android.view.view;/** * @ 7 methods and four-state  * */public class MainActivity  in the life cycle of deprecated   activity Extends activity {/** * activity is created when called  *  can initialize UI components in this method  *  The method call is complete and calls the OnStart () method  * */     @Override     protected  Void oncreate (bundle savedinstancestate)  {         Super.oncreate (savedinstancestate);         setcontentview ( R.layout.activity_main);         system.out.println (" Mainactivity-oncreate () ");     }    /**     *   is called by OnCreate (), at this time the activity courseware, but cannot be manipulated      *  the method calls the Onresume () or OnStop () method      * */     @Override     protected void onstart ()  {    // TODO  Auto-generated method stub    super.onstart ();     System.out.println ("Mainactivity-onstart ()");    }   /**     *  called when an activity in the stop state gets focus again     *  the method calls the OnStart method      *     *     * */     @Override     protected void onrestart ()  {    // TODO  Auto-generated method stub    super.onrestart ();     System.out.println ("Mainactivity-onrestart ()");    }    /**      *  called by OnStart (), the activity is visible and interactive,     *  at this time, activity is active (Running) state       *      * */     @Override      Protected void onresume ()  {    super.onresume ();     System.out.println ("Mainactivity-onresume ()");    }    /**      *  when activity is in the running state, overridden by other activity (bit-full override call)      *  Activity is paused, loses focus, is not operational      *  activity can be killed in this state       *  If the user returns to the activity, the Onresume method is called and the focus is retrieved again      * */      @Override     protected void onpause ()  {    //  todo auto-generated method stub    super.onpause ();     system.out.println ("MainactivitY-onpause () ");    }    /**     *  Called when activity is completely overwritten by another activity      *  activity goes into a stopped state, completely invisible       *  the activity can be killed in this state      *  when the user returns to the activity, the restart method is called      *      *      *  */     @Override     protected void onstop ()  {     // TODO Auto-generated method stub     Super.onstop ();     system.out.println ("Mainactivity-onstop ()");     }     /**     *  called when the activity invokes the finish method or is destroyed by the system       *  can do the work of releasing resources in this method      * */    @ Override    protected void&nbSp;ondestroy ()  {    // TODO Auto-generated method stub     super.ondestroy ();     system.out.println ("MainActivity-onDestory ()");     }     @Override     public boolean  Oncreateoptionsmenu (Menu menu)  {        // inflate  the menu; this adds items to the action bar if it  is present.        getmenuinflater (). Inflate (R.menu.main,  menu);        return true;    }     /**     *  Use this method to jump to the Activity2 interface */    public  void gotoactivity2 (view v) {    //creates an intent     intent  intent=new intent (This,mainacTivity2.class);     //start another activity    startactivity (intent);     }    }
Package com.example.android.active;import android.app.activity;import android.os.bundle;import  android.view.Menu;public class MainActivity2 extends Activity{/** *  When activity is created, call  *  can initialize the UI component in the method  *  the method call is finished calling the OnStart () method  * */      @Override     protected void oncreate (bundle savedinstancestate)   {        super.oncreate (savedinstancestate);         setcontentview (R.layout.activity_main);         system.out.println ("Mainactivity2-oncreate ()");     }    /**      *  is called by OnCreate (), at this time the activity courseware, but cannot be manipulated      *  The method calls the Onresume () or OnStop () method      * */     @Override      protected void&Nbsp;onstart ()  {    // TODO Auto-generated method stub     super.onstart ();     system.out.println ("Mainactivity2-onstart ()");     }   /**    *  called when an activity in the stop state acquires focus again      *  the method calls the OnStart method     *     *      * */     @Override     protected void  Onrestart ()  {    // TODO Auto-generated method stub     super.onrestart ();     system.out.println ("Mainactivity2-onrestart ()");     }    /**     *  is called by OnStart (), The activity is visible interactively,     *  at this point, the activity is in the active (Running) state      *       * */     @Override     protected void onresume ()  {     super.onresume ();     system.out.println ("MainActivity2-onResume ()" );    }    /**     *  when the activity is in a running state, Overridden by other activity (full-bit override call)      *  activity is paused, loses focus, not operational       *  the activity can be killed in this state      *  if the user returns to the activity, then the Onresume method is called and the focus is retrieved again      * */     @Override     protected  void onpause ()  {    // todo auto-generated method stub     super.onpause ();     system.out.println ("MainActivity2-onPause ()");     }    /**     *  Called when the activity is completely overwritten by another activity      *  This activity goes to a stop state, completely invisible      *  activity can be killed in this state       *  when the user returns to activity, the restart method is called      *       *      * */     @Override      protected void onstop ()  {    // todo auto-generated  method stub    super.onstop ();     system.out.println (" Mainactivity2-onstop () ");     }    /**     *   Called when activity invokes the finish method or is destroyed by the system      *  can be used to release resources in the method       * */     @Override     protected void  OnDestroy ()  {    // TODO Auto-generated method stub     super.ondestroy ();    system.out.println ("Mainactivity2s-ondestory ()");    }      @Override     public boolean oncreateoptionsmenu (menu menu)  {         // Inflate the menu; this adds  items to the action bar if it is present.         getmenuinflater (). Inflate (R.menu.main, menu);         return true;    }}

File configuration

 <application        android:allowbackup= "true"          android:icon= "@drawable/ic_launcher"          android:label= "@string/app_name"         android:theme= "@ Style/apptheme " >        <activity             android:name= "Com.example.android.active.MainActivity"              android:label= "@string/app_name"  >             <intent-filter>                 <action android: Name= "Android.intent.action.MAIN"  />                  <category android:name= "Android.intent.category.LAUNCHER"  />             </intent-filter>         </activity>                                   <activity            android:name= ". MainActivity2 "                   >          </activity>     </application>
<relativelayout xmlns:android= "Http://schemas.android.com/apk/res/android"      xmlns:tools= "Http://schemas.android.com/tools"     android:layout_width= "Match_parent"     android:layout_height= "Match_parent"     android:paddingbottom= "@ Dimen/activity_vertical_margin "    android:paddingleft=" @dimen/activity_horizontal_margin "     android:paddingright= "@dimen/activity_horizontal_margin"      android:paddingtop= "@dimen/activity_vertical_margin"     tools:context= ". Mainactivity " >    <TextView         Android:id= "@+id/textview1"         android:layout_width= "Wrap_content"         android:layout_height= "Wrap_content"          android:text= "@string/hellO_world " />    <button        android: Id= "@+id/button1"         style= "Android:attr/buttonstylesmall"          android:layout_width= "Wrap_content"          android:layout_height= "Wrap_content"         android: layout_below= "@+id/textview1"         android:layout_marginleft= "15DP"         android:layout_margintop= "32DP"          android:layout_torightof= "@+id/textview1"          Android:text= "Start the second activity"          android:onclick= " GotoActivity2 "/></relativelayout>

Run the project

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/8B/4D/wKioL1hJV2bxrJEuAAA-pQJL8Bs336.png-wh_500x0-wm_3 -wmp_4-s_262168621.png "title=" u1r@ (D) x@al@mlg{0l3md ' 7.png "alt=" Wkiol1hjv2bxrjeuaaa-pqjl8bs336.png-wh_50 "/>

After you click Start a second activity

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/8B/51/wKiom1hJV7HSCbo4AAA-U-bdmJo154.png-wh_500x0-wm_3 -wmp_4-s_2043523409.png "title=" $KRUCWL {[DTR6] 20d~qu7zt.png "alt=" Wkiom1hjv7hscbo4aaa-u-bdmjo154.png-wh_50 "/>

When you click the Back button

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/8B/4D/wKioL1hJV-2Bwr-xAABKQSvQIos999.png-wh_500x0-wm_3 -wmp_4-s_2910803142.png "title=" 6_}uzp5f$zb1zkjb ' Kcmcux.png "alt=" Wkiol1hjv-2bwr-xaabkqsvqios999.png-wh_50 "/>

650) this.width=650; "Src=" Http://s1.51cto.com/wyfs02/M00/8B/51/wKiom1hJWYXjAJVmAADWc9XD3KY267.png-wh_500x0-wm_3 -wmp_4-s_1865179327.png "title=" XH) [ylk2o$tbwp{m~s1p9 ' D.png "alt=" Wkiom1hjwyxjajvmaadwc9xd3ky267.png-wh_50 "/>

This article is from the "matengbing" blog, make sure to keep this source http://matengbing.blog.51cto.com/11395502/1880918

Android page switching and execution order of common methods

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.