The life cycle of "Android Essentials" activity

Source: Internet
Author: User

Google Developer Documentation
Http://developer.android.com/reference/android/app/Activity.html

Each page of the app is an activity that is stored in an activity stack, and each time it enters an application or an interface of an application, the activity is pushed to the top of the activity stack. When exiting or returning, the activity on the top of the stack pops up, and the activity goes to the top of the stack.

Four states in the activity life cycle
-Running:activity is located at the front desk (top of the stack) and is visible to the user, gaining focus
-Paused: Other activity in the foreground, currently active in the stack, but not at the top of the stack, can not get the focus
-Stopped: Current activity is not visible, loses focus, waits for system to end
-Destroy:activity end or end of Dalvik process

Life cycle diagram of activity

The activity's life cycle is clearly visible through this diagram.

As you can see, there are 7 methods that will be recalled by the system during the activity's life cycle:
-OnCreate (Bundle savedstatus): When you create an activity
-OnStart (): When you start activity
-Onrestart (): When you restart activity
-Onresume (): This method must be called after the OnStart method when the activity is resumed
-OnPause (): When activity is paused
-OnStop (): When activity is stopped
-OnDestroy (): When the activity is destroyed

In development, the most basic is to overwrite the OnCreate method, for the control initialization, in addition, OnPause can be used in the game to save the phone when the state, Onresume used to hang up the phone after the recovery state; Onresume method can also be used to refresh data on return, etc.

 Public  class Activity extends applicationcontext {     protected void onCreate(Bundle savedinstancestate);protected void OnStart();protected void Onrestart();protected void Onresume();protected void OnPause();protected void OnStop();protected void OnDestroy(); }

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The life cycle of "Android Essentials" activity

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.