How to add flags with my intent in the manifest file

20,124

Solution 1

In manifest file you can not add Intent flags.You need to set the flag in Intent which u pass to startActivity. Here is a sample:

Intent intent = new Intent(this, ActivityNameToLaunch.class);
intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
startActivity(intent);

Solution 2

To answer the original question, since this appears as the first answer in the google search, it can be done, since API level 3 (introduced in 2009) with adding android:noHistory="true" to the activity definition in the manifest file as described here: http://developer.android.com/guide/topics/manifest/activity-element.html#nohist.

example:

<activity
   android:name=".MainActivity"
   android:label="@string/app_name"
   android:noHistory="true">
  <intent-filter>
      <action android:name="android.intent.action.MAIN"/>
      <category android:name="android.intent.cataegory.LAUNCHER"/>
  </intent-filter>
</activity>

Solution 3

I had a similar problem and wanted to set the flags

Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK

in order to bring the activity always to top.

In this scenario, the solution is to set the attribute

android:launchMode="singleInstance"

in the manifest.

Generally, there are many attributes in the Android manifest for an activity, and you may play around with these to get similar effects as with flags.

Share:
20,124
Ankit
Author by

Ankit

Updated on September 27, 2020

Comments

  • Ankit
    Ankit almost 4 years

    we know that there are flags which we can add to our intent using the addFlags() method in our java code. Is there any way we can add these flags in the manifest file itself instead of writing this in java code. I need to add REORDER_TO_FRONT flag for one of my activities in the manifest.

    How to achieve this ?