How to add flags with my intent in the manifest file

Viewed 21372

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 ?

4 Answers

You can easily achieve this with using android:launchMode="singleTop" in the <activity> node of manifest, like this:

<activity
    android:name=".ui.activities.MainActivity"
    android:launchMode="singleTop">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
</activity>

Note, that android:launchMode="singleInstance" as it is given by @jörg-eisfeld is not recommended option for general use, as it is stated in official documentation: https://developer.android.com/guide/topics/manifest/activity-element.html (see the android:launchMode section)

Related