Life cycle and startup mode for Android activity

Source: Internet
Author: User

Activity is the basic of Android development in every project that will have activity. Activity has its own life cycle, there are many blogs and materials on the Internet, here I just confirm.

An activity:

There are three ways to go when you open an activity

OnCreate
OnStart
Onresume

When you click Fallback activity

OnPause
OnStop
OnDestroy

When I click on the home button

OnPause
OnStop

Open the app again

Onrestart
OnStart
Onresume

When the program crashes, don't walk the life cycle

When there are two activity, the first activity name is tentatively positioned Frist, and the second one is second

When you start the first activity

Frist:oncreate

Frist:onstart

Frist:onresume

When you open a second activity

Frist:onpause
Second:oncreate
Second:onstart
Second:onresume
Frist:onstop

When the second activity is rolled back

Second:onpause
Frist:onrestart
Frist:onstart
Frist:onresume
Second:onstop
Second:ondestroy

In the second activity click Home

Second:onpause
Second:onstop

Open the app again

Second:onrestart
Second:onstart
Second:onresume

Activation mode of activity

Standard: Normal mode, each time an activity is started, a new instance will be built, regardless of whether the instance already exists

Singletop: Stack top multiplexing mode, if the new activity is already at the top of the task station's stack, then the activity will not be recreated, and its Onnewintent method will be called, and the parameters of this method can be used to fetch the information of the current request.

Singletask: In-stack multiplexing mode, which is a single-instance mode in which the activity is not recreated as long as it exists in a stack, and as with Singletop, the system calls its onnewintent

Singleintance: Single-instance mode, a strengthened Singletask mode, in addition to having all the features of the Singletask mode, the activity of this mode can only be isolated in the task stack, due to the characteristics of the reuse in the stack, Subsequent requests do not create new activity unless the task stack is destroyed by the system

GitHub Address Https://github.com/tempest1/AndroidActivity

Life cycle and startup mode for Android 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.