Startup mode for Android activity

Source: Internet
Author: User

1. Standard

Standard mode, which is the default startup mode for the activity, which is automatically used by all activities without displaying the specified condition.

Android uses the return stack management activity, in standard mode, whenever a new activity is started, it is placed in the stack on the back of the stack and at the top of the stack.

For example:

1  Public classFirstactivityextendsappcompatactivity {2 @Override3     protected voidonCreate (Bundle savedinstancestate) {4         Super. OnCreate (savedinstancestate);5         //Prompt Information6Toast.maketext ( This, "firstactivity" + This, Toast.length_short). Show ();7 Setcontentview (r.layout.activity_first);8Button BTN =Findviewbyid (R.ID.BTN1);9Btn.setonclicklistener (NewView.onclicklistener () {Ten @Override One              Public voidOnClick (View v) { AIntent Intent =NewIntent (firstactivity. This, Firstactivity.class); - startactivity (intent); -             } the         }); -     } -}
Firstactivity.java

As you can see from the output information, when you click New Activity, a new event is created and the OnCreate method is executed.

2. Singletop

  If you want to start an activity, the activity will not be created again at the top of the stack, and the activity will still be created if the activity is not on top of the stack.

There may be times when the absolute standard mode is not very reasonable, the activity is already on the top of the stack, why do you want to start a new activity?

Set to Singletop mode:

1 <activity android:name= ". Firstactivity "2     android:launchmode=" Singletop ">3     <intent-filter>4         <action android:name= "Android.intent.action.MAIN"/>5         <category android:name= " Android.intent.category.LAUNCHER "/>6     </intent-filter>7 </activity>

3.singleTask

The goal is to have an activity that only has one instance in the context of the entire application . Each time the activity is started, the system first checks to see if the activity is present in the return stack, only if it does not exist, and if found, uses the return stack activity directly.

4.singleInstance

Start a new return stack to manage this activity.

To implement multiple program sharing activities, multiple applications share this return stack.

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.