Home » Android » Android deep-linking. Intent doesn't reset when app is opened from history

Android deep-linking. Intent doesn't reset when app is opened from history

Posted by: admin May 14, 2020 Leave a comment


I have a problem regarding Android task and intent management.


  1. User gets a push with a deep-link into the app.
  2. We show a notification putting the URI into the Intent Data.
  3. User clicks the notification and is taken into the app and redirected to some Feature1Activity described by the deep-link.
  4. User looks around, and backs out of the app.
  5. Later, user opens the app from history (long-press home or multitasking button).
  6. Now the same intent that were used from the notification (with the deep-link in the Intent Data) is used to start the app.
  7. Hence, user is taken into the Feature1Activity again.


Starting the app from history (long-press home or multitasking button) does not reset the Task (which it does when launching from app icon).

I understand that starting an app from history is not supposed to reset the task since it is intended to be used as “get-right-back-where-you-were”. However, in my case this is an issue since the launch of the app from a notification is a one time thing.

Anyone else encountered this problem? Anyone know any solution?

More in-depth

The intent inside the PendingIntent is built like this:

Intent intent = new Intent (Intent.ActionView);
intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags (Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setData (Uri.Parse (DEEP_LINK_URL));

I found out about the FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET just this day and really thought that it would git rid of my problem but it made no difference.

There are three activities of interest:

SplashActivity       (main launcher & listener of the deep-linking schema -- this activity just redirects either to login or OverviewActivity)
OverviewActivity     (authorized user's main activity)
Feature1Activity     (any feature that the deep-link is pointing to)

What happens when the user clicks the notification is that the SplashActivity acts as a listener for the schema and converts the deep-link url to two intents to start up OverviewActivity and Feature1Activity using Activity.startActivities (Intent[]).

When I look at the intent from the notification inside SplashActivity it always contain the deep-link in the Data.

One work around

There is a work around, setting some booleanExtra field to the notification intent (for instance “ignoreWhenLaunchedFromHistory” = true) and then check in SplashActivity before redirecting


if (fromHistory && getIntent().getBooleanExtra ("ignoreWhenLaunchedFromHistory", false))
    // Don't follow deep-link even if it exists
    // Follow deep-link

Except that it hackish and ugly, can you see any problems with this work around?

EDIT: The work around only works when I am responsible for sending the Intent with the deep-link. Since no external source can know about the “ignoreWhenLaunchedFromHistory” extra.

How to&Answers:

From what I get, maybe using android:excludeFromRecents="true"on your manifest (as a property for the Activity declaration) might ameliorate the issue?