Disable back button in android

后端 未结 17 1330
名媛妹妹
名媛妹妹 2020-11-22 05:10

How to disable back button in android while logging out the application?

17条回答
  •  隐瞒了意图╮
    2020-11-22 06:03

    If looking for a higher api level 2.0 and above this will work great

    @Override
    public void onBackPressed() {
        // Do Here what ever you want do on back press;
    }
    

    If looking for android api level upto 1.6.

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {
         if (keyCode == KeyEvent.KEYCODE_BACK) {
         //preventing default implementation previous to android.os.Build.VERSION_CODES.ECLAIR
         return true;
         }
         return super.onKeyDown(keyCode, event);    
    }
    

    Write above code in your Activity to prevent back button pressed

提交回复
热议问题