哦慧君

急がないで平気だって私の新年の願いだ

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

@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.



阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/nonosama0125/article/details/52352959
上一篇android 监听蓝牙开启关闭
下一篇android 文件存储
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭