Disable back button in android

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

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

17条回答
  •  我寻月下人不归
    2020-11-22 05:55

    Just override the onBackPressed() method and no need to call the super class of onBackPressed method or others..

    @Override
    public void onBackPressed()
    {
    
    }
    

    Or pass your current activity into the onBackPressed() method.

    @Override
    public void onBackPressed()
    {
       startActivity(new Intent(this, myActivity.class));  
       finish();
    }
    

    Replace your require activity name to myActivity.

    if you are using fragment then first of all call the callParentMethod() method

    public void callParentMethod(){
        context.onBackPressed(); // instead of context use getActivity or something related
    }
    

    then call the empty method

    @Override
    public void onBackPressed()
    {
    
    }
    

提交回复
热议问题