Activity startup mode

Source: Internet
Author: User

Standard mode: The default starting mode, without setting, all activities will automatically use this mode. Android uses the task stack to manage the activity, and in this mode, whenever a new activity is started, it is placed in the stack on the task stack and at the top of the stack. For this mode, the system does not care whether the activity is already in the stack, and each startup creates a new instance of the activity.

 Packagecom.pingyijinren.helloworld.activity;Importandroid.content.Intent;Importandroid.support.v7.app.AppCompatActivity;ImportAndroid.os.Bundle;ImportAndroid.view.View;ImportAndroid.widget.Button;ImportCOM.PINGYIJINREN.HELLOWORLD.R; Public classMainactivityextendsAppcompatactivityImplementsView.onclicklistener {Privatebutton button; @Overrideprotected voidonCreate (Bundle savedinstancestate) {Super. OnCreate (savedinstancestate);        Setcontentview (R.layout.activity_main); Button=(Button) Findviewbyid (R.id.button); Button.setonclicklistener ( This); } @Override Public voidOnClick (View v) {startactivity (NewIntent ( This, Mainactivity.class)); }}

A new activity is generated each time a button is clicked, at which time there are four mainactivity in the back stack and four times in a row to exit the program.

Singletop mode: When the activity is at the top of the stack and already exists, it is no longer in the stack (no longer creates an activity), and when it is not at the top of the stack, it continues into the stack.

Singletask mode: The use of this mode can be a good solution to the problem of duplicate creation of the top of the stack, when the active startup mode is specified as Singletask, each time the activity is started, the system will first check the task stack for the existence of the active instance, if the discovery already exists then directly use the instance, And the activities above the activity are all out of the stack, if not found to create an instance.

SingleInstance mode: Activities specified as singleinstance mode enable a new return stack to manage this activity (in fact, a new return stack is started if the Singletask mode has a different taskaffinity).

Activity startup mode

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.