问题
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?
回答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.
来源:https://stackoverflow.com/questions/16482413/how-to-not-show-app-on-recent-apps-list-in-ics-excludefromrecents-doesnt-work