FinishAndRemoveTask() 在 API 21 上可用 [英] finishAndRemoveTask() available on API 21

查看:45
本文介绍了FinishAndRemoveTask() 在 API 21 上可用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会终止我的应用并从最近的任务列表中取消它.

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

finishAndRemoveTask() 仅在 API 21 上可用.

finishAndRemoveTask() is available only on API 21.

我应该在低于 21 的 API 上使用什么??

What should I use on API lower than 21??

推荐答案

对堆栈中的第一个活动进行意图并完成当前活动:

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();

并且,在 FirstActivityonResume 方法中,像这样完成堆栈中的最后一个活动(并希望从最近的应用程序列表中删除该应用程序):

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();
}

这篇关于FinishAndRemoveTask() 在 API 21 上可用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆