Description of parameters for Android acitvityaction, flag, and category

Source: Internet
Author: User

Activity is responsible for displaying the user interface, but it also has a lot of knowledge to start an activity. It contains several parameters, such as action, flag, and category, action is used to implicitly start the activity, for example, with Android. provider. settings. action_settings: The action activity can start the settings interface. This is nothing. The final learning is flag. The SDK documentation defines a lot of flag. I use:

Flag_activity_new_task, which is used to start a new task.

Flag_activity_clear_top is used to refresh the interface, that is, to remove all the previously started interfaces and the above activities, and then restart the activity. This flag is used for listview refresh.

Flag_activity_clear_when_task_reset, there is a problem during interface sharing, that is, the data attached to acitivity will not be refreshed, so this flag can always keep the data in acitivity as the latest data, the data in the latest started activity prevails.

Note: When the service in this package starts an external activity, the flag: flag_activity_new_task must be added. However, sometimes you need to determine whether the outsourced acitvity has been started, if a new instance is no longer started, but flag_activity_new_task cannot guarantee this, you need to track the currently running task to check whether the task contains thisProgramIf yes, do not do anything. Otherwise, start the acitvity, instance as a new task.CodeAs follows:

Public void startkld ()

{
Boolean on = false;
System. Out. println ("Di Dong di tu! ");
Activitymanager AM = (activitymanager) getsystemservice (activity_service );
List <activitymanager. runningtaskinfo> tasklist = aM. getrunningtasks (20 );
For (INT I = 0; I <20; I ++)
{

Componentname Cn = tasklist. Get (I). topactivity;
String STR = cn. getpackagename ();
System. Out. println (STR );
If ("com. Kid". Equals (CN. getpackagename ()))
{
On = true;
Break;

}
}

If (! On)
{

Intent in = new intent ();
In. setflags (intent. flag_activity_new_task );
Componentname COM = new componentname ("com. KlD", "com. KlD. kldmap ");
In. setcomponent (COM );
Onekeynavigationservice. This. startactivity (in );
 
}

Appendix: The get_tasks permission must be added.

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.