Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

finishAndRemoveTask() available on API 21

I would terminate my app and cancel it from the list of recent task.

finishAndRemoveTask() is available only on API 21.

What should I use on API lower than 21??

like image 513
user3253955 Avatar asked Dec 08 '14 22:12

user3253955


1 Answers

Make an intent to the first activity in the stack and finish the current activity:

Intent intent  = new Intent(this, FirstActivity.class);
intent.putExtra(EXTRA_FINISH, true);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);        
startActivity(intent);
finish();

And, in the onResume method of the FirstActivity, something like this to finish the last activity in the stack (and hopefully removing the app from the recent apps list):

if (getExtras() != null && getIntentExtra(EXTRA_FINISH, false)) {
   finish();
}
like image 172
thelawnmowerman Avatar answered Oct 16 '22 14:10

thelawnmowerman