Android-activity the execution process

Source: Internet
Author: User

Overview

The following diagram shows the important state paths of an Activity. The square rectangles represent callback methods you can implement to perform operations when t He Activity moves between states. The colored ovals is major states the Activity can in.

On the official website, see this picture, even the official website oneself all say very important diagram, can't help to cut a picture:

There is three key loops you is interested in monitoring within your activity:

  • the entire lifetime of an activity happens between the first call to onCreate (Bundle) th Rough to a, final call to OnDestroy () . An activity would do all setup of ' global ' state in OnCreate (), and release all remaining resources in OnDestroy (). For example, if it had a thread running in the background to download data from the network, it could create that thread in OnCreate () and then stop the thread in OnDestroy ().
  • the visible lifetime of an activity happens between a call to OnStart () until a correspo Nding Call to onStop () . During this time the user can see the activity on-screen, though it may isn't is in the foreground and interacting with the User. Between these, methods you can maintain resources, is needed to show the activity to the user. For example, you can register a broadcastreceiver in OnStart () to monitor for changes the impact your UI, an D Unregister it in OnStop () then the user no longer sees what is displaying. The OnStart () and OnStop () methods can is called multiple times, as the activity becomes visible and hidden to the user.
  • the foreground lifetime of an activity happens between a call to Onresume () until a Corr Esponding Call to OnPause () . During this time, the activity is in front of any other activities, and interacting with the user. An activity can frequently go between the resumed and paused states – for example when the device goes to sleep Activity result was delivered, when a new intent was delivered--the code in these methods should was fairly lightweight.

The entire lifecycle of an activity are defined by the following activity methods. All of these is hooks that you can override to do appropriate work when the activity is changes state. All activities would implement to do onCreate(Bundle) their initial setup; many would also implement to onPause() commit changes to data an D otherwise prepare to stop interacting with the user. You should all call up to your superclass when implementing these methods.

 Public classActivityextendsApplicationContext {protected voidonCreate (Bundle savedinstancestate); protected voidOnStart (); protected voidOnrestart (); protected voidOnresume (); protected voidOnPause (); protected voidOnStop (); protected voidOnDestroy ();}

Android-activity the execution process

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.