Android: Recents starts incorrect activity
<p>I am developing an android app which has 2 methodes of starting. 
One is the normal way by pressing the app icon on the phone.
The other method is with a deep link from a website.</p>

<p>The deeplink also sends some data which the app needs to do some "stuff". However this should only be done once. 
When the deeplink activity is finished it start the main activity. However when I press back (on the device) and open the app from recents it opens the deeplink activity again.</p>

<p>I could exclude the deeplink activity from the recents in the manifest. This also excludes the mainactivity from the recent apps, this should not be the case.</p>

<p>How do I prevent the deeplink activity from beeing started from the recent apps?</p>

<p>My Manifest:</p>

<pre><code>   &lt;activity
        android:name="MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="portrait"
        android:launchMode="singleTask"
        android:theme="@style/AppTheme"&gt;
    &lt;/activity&gt;

    &lt;activity
        android:name="DeeplinkActivity"
        android:label="@string/app_name"
        android:noHistory="true"
        android:screenOrientation="portrait"
        android:launchMode="singleTask"
        android:theme="@style/AppTheme"&gt;

        &lt;intent-filter&gt;
            &lt;action android:name="android.intent.action.VIEW" /&gt;
            &lt;category android:name="android.intent.category.DEFAULT" /&gt;
            &lt;category android:name="android.intent.category.BROWSABLE" /&gt;
            &lt;data android:scheme="app_name" android:host="test" /&gt;
        &lt;/intent-filter&gt;

        &lt;intent-filter&gt;
            &lt;action android:name="android.intent.action.VIEW" /&gt;
            &lt;category android:name="android.intent.category.DEFAULT" /&gt;
            &lt;category android:name="android.intent.category.BROWSABLE" /&gt;
            &lt;data android:host="test" android:path="/" android:scheme="app_name" /&gt;
        &lt;/intent-filter&gt;
    &lt;/activity&gt;
</code></pre>

<p>To switch to the MainActivity I do the following:</p>

<pre><code>        Intent intent = new Intent(this, MainActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        startActivity(intent);
</code></pre>

<p>EDIT:
This post was marked as duplicate with: <a href="https://stackoverflow.com/questions/4866149/android-starting-app-from-recent-applications-starts-it-with-the-last-set-of">Android: Starting app from &#39;recent applications&#39; starts it with the last set of extras used in an intent</a></p>

<p>However that post is regarding the same activity. I want to change the root activity so when I start the app from recents it does not start the DeeplinkActivity. Yes as a workaround I could check the Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY flag. But then every time the user starts the app from recents the DeeplinkActivity is opened whilst it is not needed anymore.</p>

<p>Setting and or clearing aditional intent values does not seem to work.
I use information from the getIntent().getData()</p>

<p>If you still feel as if this is a duplicate please explain.</p>