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

后端 未结 20 2052
伪装坚强ぢ
伪装坚强ぢ 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:04

    Here's what i did:

    SomeActivity.java

     @Override
        public void onBackPressed() {
                Intent newIntent = new Intent(this,QuitAppActivity.class);
                newIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
                startActivity(newIntent);
                finish();
        }
    

    QuitAppActivity.java

    @Override
    protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          finish();
    }
    

    Basically what you did is cleared all activities from the stack and launch QuitAppActivity, that will finish the task.

提交回复
热议问题