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

android 监听当前页返回键回到桌面,再次点击app回到当前页

2016-08-29 14:39 549 查看
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch(keyCode){
case KeyEvent.KEYCODE_BACK:
Intent home = new Intent(Intent.ACTION_MAIN);
home.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
home.addCategory(Intent.CATEGORY_HOME);
startActivity(home);
return true;
}
return super.onKeyDown(keyCode, event);
}


 
FLAG_ACTIVITY_NEW_TASK

If set, this activity will become the start of a new task on this history stack.

ACTION_MAIN

Added in
API level 1
String ACTION_MAIN

Activity Action: Start as a main entry point, does not expect to receive data.

CATEGORY_HOME


This is the home activity, that is the first activity that is displayed when the device boots.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐