0

How to close recent activities(press and hold button home) when activity started from services?

Tried android:excludeFromRecents="true" and android:noHistory="true", but it works if I close manual from myActivity. But, when close finish() from services using Broadcast Receiver, it doesn't work.

So, how to close recent activities when it close automatic from services? Please help . .

Dharmendra Pratap Singh
  • 1,332
  • 1
  • 11
  • 22
virho
  • 149
  • 2
  • 2
  • 9

2 Answers2

0

This works for clear history from recent apps:

android.os.Process.killProcess(android.os.Process.myPid());
KOTIOS
  • 11,177
  • 3
  • 39
  • 66
0

Actually you have to clear the activity stack content. In API level 11 or greater, use FLAG_ACTIVITY_CLEAR_TASK and FLAG_ACTIVITY_NEW_TASK flag on Intent to clear all the activity stack.

    Intent i = new Intent(OldActivity.this, NewActivity.class);
// set the new task and clear flags
i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK)
startActivity(i);
Namo
  • 157
  • 1
  • 6
  • 17