I have three activities:
A,B,C
A is home screen.
Activities are launched as follow A->B->C
If I come to home screen using backbutton, I want to clear activity stack/previous activities history and it should exit the application.
Can anyone guide me how to achieve this?
Very simple: use intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
on an intent used to start the activity A.
You can do following:
1. Set clearTaskOnLaunch = "true"
in AndroidManifest, in declaration of activity A
2. In activity C:
@Override
public void onBackPressed(){
moveTaskToBack(true);
}
So if user presses back - it comes back to homescreen.
If user launches application again - task stack clears and he comes to root activity (A)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With