I was reading this question because I want to create an exit button for my android app. I found the following answer
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addCategory(Intent.CATEGORY_HOME);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
but I don't understand why he set the flag Intent.FLAG_ACTIVITY_NEW_TASK
. What exactly this flag is gonna do? Can I omit it? Which is the best approach?
By the way I got confused when I read
the current task will simply be brought to the front of the screen with the state it was last in
from the official documentation (here). I thought that FLAG_ACTIVITY_NEW_TASK will create a new back-stack and hence lose the state it was last in...