Back button works like home

后端 未结 4 400
挽巷
挽巷 2021-01-17 05:11

Is it possible to change this code:

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK) {

    }
             


        
4条回答
  •  生来不讨喜
    2021-01-17 05:36

    try this,

    @Override
        public void onBackPressed() {
            Intent backtoHome = new Intent(Intent.ACTION_MAIN);
            backtoHome.addCategory(Intent.CATEGORY_HOME);
            backtoHome.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(backtoHome);
        }
    

    Adding this to your Activity, will make it look like your app is responding to a Home Button Click event

提交回复
热议问题