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
- 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
- finishAndRemoveTask () - Official Doc -> not available below 21
- System.exit(0) - not working
- android.os.Process.killProcess(android.os.Process.myPid()) - not working