您的位置:首页 > 移动开发 > Android开发

android返回主页时,Activity在后台继续运行的方法

2016-04-10 22:57 387 查看
android中实现应用程序的Activity按返回键时,不销毁该Activity,在后台继续运行

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
moveTaskToBack(false);
return true;
}
return super.onKeyDown(keyCode, event);
}


其中主要起作用的代码是:moveTaskToBack(false);这一行代码;

其API文档描述如下 :

Move the task containing this activity to the back of the activity stack. The activity’s order within the task is unchanged.

参数:

nonRoot If false then this only works if the activity is the root of a task; if true it will work for any activity in a task.

返回:

If the task was moved (or it was already at the back) true is returned, else false.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息