Android-Life cycle

Source: Internet
Author: User

Android life cycle diagram

Android life cycle, top down, below we pass a simple demo, each life cycle.

Through demo instructions

1, here my mainactivity rewrite the 7 methods of the parent class (the method of gray shading in the figure)
Code

 PackageCom.example.helloworld;ImportAndroid.os.Bundle;Importandroid.app.Activity;ImportAndroid.view.Menu; Public  class mainactivity extends Activity {    @Override    protected void onCreate(Bundle savedinstancestate) {Super. OnCreate (Savedinstancestate); System.out.println ("OnCreate");    Setcontentview (R.layout.activity_main); }@Override    protected void OnStart() {Super. OnStart (); System.out.println ("Onstrat"); }@Override    protected void Onresume() {Super. Onresume (); System.out.println ("Onresume"); }protected void OnPause() {Super. OnPause (); System.out.println ("OnPause"); }protected void OnStop() {Super. OnStop (); System.out.println ("OnStop"); }protected void OnDestroy() {Super. OnPause (); System.out.println ("OnDestroy"); }protected void Onrestart() {Super. Onrestart (); System.out.println ("Onrestart"); }@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; }}

2. Launch apk, view log, output sequence Oncreate->onstart->onresume

3, in our mobile phone keys have 2 exit button, one is home, one is the return button.

4, we click the Home button (small house), output order Onpause->onstop

5, then we go into the application, we can look at the life cycle diagram, compared to, that is, click on the home exit, the application is thrown in the background, not destroyed, start again, do not need to call the OnCreate method

6, below we click, return button exit, executed the Ondestory method

7, restart the application, call the OnCreate method to re-create

Through the above steps of debugging, you can analyze an application from start to exit, to restart the background of a running situation.

Android-Life cycle

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.