How to exit from the application and show the home screen?

后端 未结 20 2279
伪装坚强ぢ
伪装坚强ぢ 2020-11-22 09:45

I have an application where on the home page I have buttons for navigation through the application.

On that page I have a button \"EXIT\" which when clicked should t

20条回答
  •  温柔的废话
    2020-11-22 10:20

    if you want to exit application put this code under your function

    public void yourFunction()
    {
    finishAffinity();   
    moveTaskToBack(true);
    
    }
    
    
    
    //For an instance, if you want to exit an application on double click of a 
    //button,then the following code can be used.
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)  {
        if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 2) {
            // do something on back.
            From Android 16+ you can use the following:
    
            finishAffinity();
            moveTaskToBack(true);
        }
    
        return super.onKeyDown(keyCode, event);
    }
    

提交回复
热议问题