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

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

    Use finishAffinity() method that will finish the current activity and all parent activities. But it works only for API 16+ mean Android 4.1 or higher.

    API 16+ use:

    finishAffinity();
    

    Below API 16 use:

    ActivityCompat.finishAffinity(this); //with v4 support library
    

    To exit whole app:

    finishAffinity(); // Close all activites
    System.exit(0);  // Releasing resources
    

提交回复
热议问题