how to finish all activities and close the application in android?

前端 未结 9 1139
自闭症患者
自闭症患者 2021-01-03 19:53

My application has the following flow:

Home->screen 1->screen 2->screen 3->screen 4->screen 5>Home->screen 2->Home->Screen 3

My problem is that when I am try

9条回答
  •  自闭症患者
    2021-01-03 20:30

    This works well for me.

    • You should using FLAG_ACTIVITY_CLEAR_TASK and FLAG_ACTIVITY_NEW_TASK flags.

      Intent intent = new Intent(SecondActivity.this, CloseActivity.class);
      //Clear all activities and start new task
      intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); 
      startActivity(intent);
      
    • onCreate() method of CloseActivity activity.

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

提交回复
热议问题