How to prevent going back to the previous activity?

前端 未结 13 1015
眼角桃花
眼角桃花 2020-11-27 09:10

When the BACK button is pressed on the phone, I want to prevent a specific activity from returning to its previous one.

Specifically, I have login and sign up screen

13条回答
  •  情深已故
    2020-11-27 10:07

    Just override the onKeyDown method and check if the back button was pressed.

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) 
    {
        if (keyCode == KeyEvent.KEYCODE_BACK) 
        {
            //Back buttons was pressed, do whatever logic you want
        }
    
        return false;
    }
    

提交回复
热议问题