Android按返回键,程序进入后台运行,不关闭程序,finishAcrivity
原创
©著作权归作者所有:来自51CTO博客作者陈振阳Plus的原创作品,请联系作者获取转载授权,否则将追究法律责任
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) { moveTaskToBack(false);
return true;
}
return super.onKeyDown(keyCode, event);
}
主要是moveTaskToBack(false);方法,源码如下
/** * Move the task containing this activity to the back of the activity * stack. The activity's order within the task is unchanged.
of a task; if true it will work for any activity in * a task. * * @return If the task was moved (or it was already at the * back) true is returned, else false. */
public boolean moveTaskToBack(boolean nonRoot) {
return ActivityManagerNative.getDefault().moveActivityTaskToBack( mToken, nonRoot);
} catch (RemoteException e) {
}
}