1

This question seems to be duplicate but it is not!

I want to close my whole application in one shot.

Note: My application may have multiple Activity Back Stack

For API level >=21 bellow code working fine

ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
if (activityManager != null) 
{
     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) 
     {
         for (ActivityManager.AppTask appTask : activityManager.getAppTasks()) 
         {
                appTask.finishAndRemoveTask();
         }
     }
}

I need code for below 21

I have tried the following solution listed bellow

  1. finishAffinity() - Official Doc First First Line-> Finish this activity as well as all activities immediately below it in the current task that have the same affinity, means it will clear current task not all the task
  2. finishAndRemoveTask () - Official Doc -> not available below 21
  3. System.exit(0) - not working
  4. android.os.Process.killProcess(android.os.Process.myPid()) - not working
Community
  • 1
  • 1
Rahul Pareta
  • 786
  • 6
  • 18

0 Answers0