Skip to content
Advertisement

With a DrawerLayout, how can I close the app on pressing Back no matter which screen is active?

I’m using a DrawerLayout for the navigation of my app:

Taking this menu for the example:

enter image description here

I’d like the Home button to launch the HomeActivity and so on. But clearing the activity stack, that is: If I press People, then Photos, then Locations and then the back button, the app should close. I’m trying intent flags when launching the activities but I always get the same behaviour: People->Photos->Location->Back goes to Photos instead closing the app

How can I achieve that?

Advertisement

Answer

As per you said that “If I press People, then Photos, then Locations and then the back button, the app should close”.

For achieve that you should user Fragment for Home,People,Location and Photos etc. and when you press back button of Device you can clear Fragment back stack and finish activity.

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