2

I am working on and Android application. When my application is running and i press the recent applications button on the phone , Activity's onPause() method is called . Inside this onPause i call finish() . So the activity gets destroyed.

But its still visible in the recent applications list.

How do i make sure it is not listed in the recent applications list when i destroy my activity from onPause().

Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
Pardeep Kr
  • 479
  • 2
  • 6
  • 25

4 Answers4

10

Try doing

<activity android:name=".MainActivity"
        android:excludeFromRecents="true" ...>

in your AndroidManifest.xml's activity declaration.

get more from official documentation

Whether or not the task initiated by this activity should be excluded from the list of recently used applications ("recent apps"). That is, when this activity is the root activity of a new task, this attribute determines whether the task should not appear in the list of recent apps. Set "true" if the task should be excluded from the list; set "false" if it should be included. The default value is "false".

when you want to have special properties for an Activity when starting it you supply special flags to the Intent. In this case FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS.

Go through link.

Community
  • 1
  • 1
Amit Vaghela
  • 22,772
  • 22
  • 86
  • 142
2

use finishAndRemoveTask() instead of finish() or finishAffinity()

ayoub laaziz
  • 1,196
  • 9
  • 12
0

The reason may be because only your activity is destroyed not the Application instance. Android awaits may be user open up the app again. To completely terminate application you can use for above API 16 this.finishAffinity() .

It will finish the current activity and all other under it. As doc says

Finish this activity as well as all activities immediately below it in the current task that have the same affinity

theJango
  • 1,100
  • 10
  • 22
0

use

finish();

when you move to the next activity then recent activity is finish

Muhammad Asad
  • 694
  • 6
  • 10