Search code examples
androidandroid-activityandroid-recents

How to set foreground application as not showing in recent list?


I know how to remove an application or activity from recent list by adding android:excludeFromRecents="true" to Manifest file. This will remove the activities when they are not in the foreground.

I tried adding the flag FLAG_ACTIVITY_CLEAR_TOP also. But, no activities on the foreground can be hidden from recent list when the home button is long pressed during that time. My activity gets killed when swiped away from the recent list, while it is in the foreground. How to remove the foreground activity or a whole foreground application from Recent list?


Solution

  • You cannot "hide" your application from the user this way. Tasks with running activities are always displayed in the list of recent tasks.

    The only way to remove your task from the list of recent tasks is to set android:noHistory="true" on all <activity> declarations in the manifest. However, this will cause the activities to be finished when the user navigates away from them (ie: presses the HOME button or the "recents" button, so this is probably not what you want.