Android - reopen main activity from notification
<p>Launcher activity for my app is called <strong>LaunchActivity</strong>. Inside this activity I check if the user is logged. If yes, then a network call is made to validate the user and if everything is fine <strong>MainActivity</strong> is started. If user runs app for first time or user validation fails, <strong>LoginActivity</strong> runs.</p>

<p>Inside LaunchActivity there is function that runs appropriate activity:</p>

<pre><code>private void start(Class&lt;? extends Activity&gt; startActivity) {

    Intent intent = new Intent(this, startActivity);
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
    finish();
    startActivity(intent);
}
</code></pre>

<p>App is receiving notifications. After notification click i want to open app or bring it top if it is on background. </p>

<p>Code responsible for notification intent:</p>

<pre><code>   Intent intent = new Intent(context, LaunchActivity.class);
    intent.putExtra("SHOW_NOTIFICATION_LIST", "");
    intent.setAction(Intent.ACTION_MAIN);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);

    PendingIntent notificationIntent = PendingIntent.getActivity(
            context,
            0,
            intent,
            0);
    builder.setContentIntent(notificationIntent);

    Notification notification = builder.build();
</code></pre>

<p>The problem is that with my current implementation after click, LaunchActivity is reopened even when MainActivity is on background. I can not figure out how to make the pending intent reopen just <strong>MainActivity</strong> (without LaunchActivity and valdation) if it is on background OR start <strong>LaunchActivity</strong> when there are no activity running on background ( app is not running ). I would be very grateful for any kind of help. </p>

<p>edit:</p>

<p>Activities declaration inside manifest:</p>

<pre><code>        &lt;activity android:name=".activities.LaunchActivity" &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=".activities.MainActivity"
        android:launchMode="singleTop"
        android:screenOrientation="userPortrait" /&gt;
    &lt;activity
        android:name=".activities.LoginActivity"
        android:excludeFromRecents="true"
        android:launchMode="singleTop"
        android:noHistory="true"
        android:screenOrientation="userPortrait"
        android:windowSoftInputMode="adjustResize" &gt;
    &lt;/activity&gt;
</code></pre>