The life cycle of activity and the role of various life cycle methods

Source: Internet
Author: User

I. The role of each method in the life cycle of the activity

OnCreate (): The initialization of the data needed to do the activity.

OnStart (): Displays the activity interface, at which time the user is visible to the interface but not interactive.

Onresume (): At this point the user can interact with the app and do what you want to do.

OnPause (): The user is visible but not interactive at this point, or the interface has no focus at this time, such as a popup dialog box.

OnStop (): The interface becomes invisible at this point and is overwritten or minimized by the next activity.

OnDestroy (): This is the last method to be called before the activity is killed.

Second, the process of invoking the life cycle method

1. When activity is started: OnCreate ()-->onstart ()-->onresume () and interacting with the user

2.onPause ()-->onresume ()

OnPause (): Not interactive at this time, usually jumping out of the dialog box. At this point you will save some of your data---transient data,

Because this time the priority of the program is reduced, it is possible to be recovered by the system. When returning, call Onresume () at Onresume () to read the

The saved data.

Note: This is done in a short time, because the next activity (): will not wait until this method is completed before starting

3.onPause ()-->onstop ()-->onstart ()-->onresume () cannot see visible and interactive

When activity is minimized or overwritten by other activity---activity is not visible at this time, the process of re-invoking the activity (this refers to

The activity is not killed by the system);

Another: If at this time the covered activity was killed by the system, the general is to restart the activity, the cycle will start again.

4.onPause ()-->onstop ()-->ondestroy ()

This is the process of activity being killed. We need to write down resources in the OnDestroy () method, such as the service associated with the activity,

Background threads, and so on.

The life cycle of activity and the role of various life cycle methods

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.