Android activity launch mode and deeplink issue
<p>My app has 2 activities.
The root activity of the app is the MainActivity. If credentials are missing or invalid the user will be redirected to the LoginActivity while finishing the MainActivity.</p>

<p>If i set the launch mode of the main activity to singleTask and I am in an inner fragment of the LoginActivity => minimize the app -> launch the app from the launcher icon => The MainActivity launches (since it is a singleTask activity) and redirects to the LoginActivity but of course to the first fragment in the stack.</p>

<p>The wanted behavior (as is happening when re-launching from recents) is that it would retain the instance of the current activity and display the correct fragment in the stack of the LoginActivity.</p>

<p>This could of course be solved easily by setting the launch mode to singleTop but then a different issue happens! DeepLink trouble!</p>

<p>If my app is open in the background and I click on a link from a browser or email when in singleTop mode - the app will be opened as a subtask of the forwarding app (if you click recents you will see your app opened twice - once as a regular instance that was there before and one enclosed within the browser/email).
This of course is tremendously inconvenient and can be solved by - well you know - setting the launch mode to singleTask!</p>

<p>Any help on this issue will be most appreciated.</p>

<pre><code>   &lt;!-- Main Activity --&gt;
    &lt;activity
        android:name=".MainActivity"
        android:label="@string/app_name"
        android:launchMode="singleTask"
        android:screenOrientation="portrait"&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;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="somehost"
                android:scheme="myscheme" /&gt;
        &lt;/intent-filter&gt;
    &lt;/activity&gt;

    &lt;!-- Login Activity --&gt;
    &lt;activity
        android:name="LoginActivity"
        android:launchMode="singleTask"
        android:screenOrientation="portrait" /&gt;
</code></pre>