Android 返回键 返回桌面 不关闭app

Updated on with 866 views

 
    //重写onKeyDown
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
        if (keyCode == KeyEvent.KEYCODE_BACK) {
            Intent home = new Intent(Intent.ACTION_MAIN);
            home.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            home.addCategory(Intent.CATEGORY_HOME);
            startActivity(home);
            return true;
        }
        return super.onKeyDown(keyCode, event);
    }


标题:Android 返回键 返回桌面 不关闭app
作者:yanjing
地址:https://yanjingtp.cn/articles/2022/02/09/1644392764918.html