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

前端 未结 9 1099
自闭症患者
自闭症患者 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:27

    There are 2 ways for solve your problem

    1) call finish() after startActivity(intent) in every activity

    2) set android:launchMode="singleInstance" in every tag in menifest file

    i think 2nd way is best for solving problem but you can also use first way

    0 讨论(0)
  • 2021-01-03 20:29

    Add android:noHistory="true" in your activity manifest file.

    0 讨论(0)
  • 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 
      }
      
    0 讨论(0)
提交回复
热议问题