In multi-activity development, activity jumps between applications or reusable activities with other applications. You may want to jump to an existing activity instance instead of generating a large number of duplicate activities.
This requires configuring a specific loading mode for the activity, rather than using the default loading mode.
Loading Mode classification and where to configure
Activity has four loading modes:
- Standard
- Singletop
- Singletask
- Singleinstance
The set location is in the Android: launchmode attribute of the activity element in the androidmanifest. xml file:
<Activity Android: Name = "actb"Android: launchmode= "Singletask"> </activity>
Package net. Blog. vtion;
Import Android. App. activity;
Import Android. content. intent;
Import Android. OS. Bundle;
Import Android. View. view;
Import Android. View. View. onclicklistener;
Import Android. widget. Button;
Import Android. widget. linearlayout;
Import Android. widget. textview;
Public class firstactivity extends activity {
/** Called when the activity is first created .*/
@ Override
Public void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Textview = new textview (this );
Textview. settext (This + "");
Button button = new button (this );
Button. settext ("Go Acta ");
Button. setonclicklistener (New onclicklistener (){
@ Override
Public void onclick (view v ){
Intent intent = new intent ();
Intent. setclass (firstactivity. This, firstactivity. Class );
Startactivity (intent );
}
});
Linearlayout layout = new linearlayout (this );
Layout. setorientation (linearlayout. Vertical );
Layout. addview (textview );
Layout. addview (button );
This. setcontentview (layout );
}
}
See the example of ACTA-> ACTA. Print the tostring value of the object on the interface to identify whether to create a new ACTA instance based on the hash code.
It can be multiple times. It is found that a new instance of the activity is created every time. The loading mode of standard is like this, and intent will send to the new instance.