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