Android standard Loading Mode

Source: Internet
Author: User

 

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.

 

 

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