6

I know it should be achievable be either android:excludeFromRecents="true" in android manifest or Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS Intent flag.

Problem is, that doesn't work if application is currently being shown - when Recent Apps button is clicked, application is always shown in the first place, allowing for quick killing of the application (by swiping it). Not good for an alarm clock app.

Music Service keeps on playing fortunately and user can get back to finishing alarm by the notification, but I have really hard time recreating activities stack.

Any quick fix available?

Koger
  • 1,783
  • 2
  • 23
  • 34
  • You are trying to circumvent the problem by stopping the user from swiping the app on recents. The app's stack can also be cleared by the user from the settings or other apps (task killers), or by the OS when the memory is needed. You need to be able to handle the notification reopening the app and creating a synthetic stack. – Steven Byle May 10 '13 at 12:51
  • Have you tried terminating your activity before it goes to background? try this.finish() on onPause() and onStop() events – Hossein Shahdoost Jul 18 '13 at 09:53

1 Answers1

1

This is a well known Android Issue: https://code.google.com/archive/p/android-developer-preview/issues/1662

This is a solution:

ActivityManager am =(ActivityManager)getSystemService(Context.ACTIVITY_SERVICE);
if(am != null) {
    List<ActivityManager.AppTask> tasks = am.getAppTasks();
    if (tasks != null && tasks.size() > 0) {
        tasks.get(0).setExcludeFromRecents(true);
    }
}

If Task Root Activity is excluded from recent, all activities in this task will be excluded too.

StepanM
  • 4,222
  • 1
  • 21
  • 25