关闭

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

489人阅读 评论(0) 收藏 举报
@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.



0
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:21179次
    • 积分:456
    • 等级:
    • 排名:千里之外
    • 原创:22篇
    • 转载:8篇
    • 译文:0篇
    • 评论:0条