Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to finish all Activities except Main Activity and call another Activity

I am implementing Drawer Navigation in my Application. On click of each item of drawer menu list i am calling another Activity and this Drawer Navigation is implemented in every activity.

Now i want to clear BackStack while calling an activity on each item click, so if i press back button then there should not be the previous activity from which user jumped to the current activity.

like image 277
Faisal Asif Avatar asked Oct 27 '25 05:10

Faisal Asif


1 Answers

Do like this-

Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP |  Intent.FLAG_ACTIVITY_SINGLE_TOP);
startActivity(intent);
like image 123
My God Avatar answered Oct 29 '25 20:10

My God



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!