I\'m implementing GCM. My app has two activities, say A
and B
. I\'m using this code to launch B
from the NotificationBar:
I also noticed that sometimes an Activity
's onCreate()
was getting stale Intent
s when launched from Recents, but there is a way to check for that so you can handle the Intent
appropriately.
JAVA:
protected boolean wasLaunchedFromRecents() {
return (getIntent().getFlags() & Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY) == Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY;
}
Kotlin:
fun wasLaunchedFromRecents(): Boolean {
val flags: Int = intent.flags and Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
return flags == Intent.FLAG_ACTIVITY_LAUNCHED_FROM_HISTORY
}
In my humble opinion, that flag is poorly named (other flags referencing the Recents list actually use that word, e.g. FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS
, FLAG_ACTIVITY_RETAIN_IN_RECENTS
) and the documentation was never updated to reflect the fact that many popular Android devices have a dedicated button for Recents:
This flag is not normally set by application code, but set for you by the system if this activity is being launched from history (longpress home key).
(N.B. I realize that you solved your issue another way years ago, but this question is one of the top search results for 'android old intent recent' and none of the other related questions mention this flag, so hopefully this Answer can help someone else.)