Skip to content

Press back button on main activity opens other activity

In my project i move from main activity to activity A and from activity A to activity B. From activity B using home menu on toolbar i jump back to main activity. Now when i press back button application should exit but it opens the activity A again.



You should make use of the launch flags to manage your activities in the back stack. As far as I understood your scenario, I think you need to use FLAG_ACTIVITY_CLEAR_TOP for starting your main/home activity.

Read more about launch flags:

Also, take a look this for more details on managing activity back stack on Android:

User contributions licensed under: CC BY-SA
2 People found this is helpful