How to not show app on recent apps list in ICS? excludeFromRecents doesn't work
Asked Answered
C

1

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?

Chaffin answered 10/5, 2013 at 12:36 Comment(2)
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.Kleiman
Have you tried terminating your activity before it goes to background? try this.finish() on onPause() and onStop() eventsHistoriated
C
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.

Charybdis answered 31/1, 2018 at 16:4 Comment(1)
This work for the foreground activity in Android 5, but doesn't work in Android 6+Anyways

© 2022 - 2024 — McMap. All rights reserved.