Prevent Android system from resuming task if the new Intent is the same with initial Intent that launches the app
<p>This question is related to deep link. For example, I have four activities in my app, namely <code>MainActivity</code>, <code>FirstActivity</code>, <code>SecondActivity</code>, and <code>DeepLinkActivity</code>. Here are the activities in the manifest file.</p>

<pre><code>&lt;activity android:name=".MainActivity"&gt;
    &lt;intent-filter&gt;
       &lt;action android:name="android.intent.action.MAIN" /&gt;
       &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
    &lt;/intent-filter&gt;
&lt;/activity&gt;
&lt;activity android:name=".FirstActivity" /&gt;
&lt;activity android:name=".SecondActivity" /&gt;
&lt;activity android:name=".DeepLinkActivity"
    android:theme="@android:style/Theme.NoDisplay"&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="launch" /&gt;
    &lt;/intent-filter&gt;
&lt;/activity&gt;
</code></pre>

<p><code>DeepLinkActivity</code> will launch whether <code>FirstActivity</code>, <code>SecondActivity</code>, or <code>MainActivity</code> depending on the URI received:</p>

<pre><code>public class DeepLinkActivity extends AppCompatActivity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        launchIntent(getIntent());
    }

    private void launchIntent(Intent intent) {
        Intent newIntent = null;

        switch (intent.getData().getHost()) {
            case "first":
                newIntent = new Intent(this, FirstActivity.class);
                break;
            case "second":
                newIntent = new Intent(this, SecondActivity.class);
                break;
            default:
                newIntent = new Intent(this, MainActivity.class);
                break;
        }

        startActivity(newIntent);
        finish();
    }
}
</code></pre>

<p>The problem is, Android system seems to record the initial Intent that launched the app, then uses it to resume whatever Activity is currently running in the foreground <strong>-if-</strong> the new Intent is the same with initial Intent.</p>

<p>Consider the following case:</p>

<ol>
<li>User click <code>launch://first</code> deep link → <code>FirstActivity</code> is opened.</li>
<li>User minimize the app then click <code>launch://second</code> → <code>SecondActivity</code> is opened on top of <code>FirstActivity</code>.</li>
<li>User minimize the app again then click <code>launch://first</code>.</li>
</ol>

<p>After step 3, what I expect is the OS open <code>FirstActivity</code>. But actually it resumes the task, so <code>SecondActivity</code> (from step 2) reappears. This happens because the deep link on step 1 and 3 is the same, hence the OS regards them as the same Intent.</p>

<p>How can I prevent the Android system from resuming task in this particular case?</p>