Android only opens one activity instance

Source: Internet
Author: User

In one activity, multiple calls to StartActivity () to start another activity, there are two ways to generate only one activity instance.

method One: Set the start Mode
An activity has four startup modes: Standard, Singletop, Singletask, SingleInstance.
Standard: Normal mode, a call to the StartActivity () method produces a new instance.
Singletop: If an instance already exists at the top of the activity stack, it does not produce a new instance, but simply invokes the newinstance () method in activity. If it is not at the top of the stack, a new instance is generated.
Singletask: this instance will be generated in a new task, which will be used for each subsequent invocation and will not produce a new instance.
SingleInstance: This is basically the same as Singletask, there is only one difference: In this mode the activity instance is in the task, only the activity instance, cannot have other instances.

These startup modes can be set in the feature manifest file in the Launchmode property in,<activity>.

method Two: Add the mark in the intent
Intent.flag_activity_reorder_to_front This sign says: If the activity has started, it will not generate new activity, but just add the activity instance to the top of the stack.

Intent Intent = new Intent (reorderfour.this, reordertwo.class);   Intent.addflags (Intent.flag_activity_reorder_to_front);   StartActivity (Intent);

Android only opens one activity instance

Related Article

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: 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.