0

I have an App with a Navigation Drawer design and some activities (I know working with Fragments would probably be easier here but that wasn't feasible).

When the user clicks a drawer item, the according Activity is started with FLAG_ACTIVITY_REORDER_TO_FRONT. The up button should always take the user back to the start activity A, so when the up button is pressed I also start the A activity with the same flag.

Consider the following (capital letters are the activities, trying to visualize the backstack here):

A

user starts B from the drawer

A -> B

user presses up button, brings A in front

B -> A

user presses back button finishing A going back to B

B 

user presses back button again which exits the application, but imho the user should always see the start Activity A again before leaving the app.

How would / did you guys solve this?

EDIT: @Neil, with that is: If I have

A -> B

and from there via drawer go to C I have

A -> B -> C

If the user now presses the Up button and I just close C instead of bringing A to the top, the user will be back in B which would be wrong because C is (navigationwise) not under B but they are 'siblings'.

fweigl
  • 21,278
  • 20
  • 114
  • 205
  • Do you `finish()` the start `Activity A` when going to `Activity B`? If not don't use the `FLAG_ACTIVITY_REORDER_TO_FRONT` just finish `Activity B` when going back to `Activity A`. – the-ginger-geek Nov 21 '13 at 08:31
  • You can do that too :) – Cyph3rCod3r Nov 21 '13 at 08:51
  • @Neil Thanks for the input, I tried that but there's a problem with that that I described in my Edit. – fweigl Nov 21 '13 at 09:03
  • When you open a new activity via the drawer you should close the previous activity. So basically Activity A will always be the parent Activity (at the bottom of the stack) and any other Activity will always be the child. You should find a way to always only have one child on top of A, so remember what activity was opened in from the drawer and then when navigating again with the drawer kill any other activity that is open and is not A. Is Activity A the activity that implements the Drawer? – the-ginger-geek Nov 21 '13 at 09:08
  • I guess I will do that. I thought when the user goes from A to B to C the back button should bring him back to B, but as B and C are siblings that probably isn't necessary. Thanks for your help :) – fweigl Nov 21 '13 at 09:14
  • Why working with fragments was not feasible? As far as the docs say thats the way to go in that situation. See: http://developer.android.com/training/implementing-navigation/descendant.html Also take a look to my answer about implementing descendant navigation with the Navigation Drawer. http://stackoverflow.com/a/20415711/1082344 – IsaacCisneros Dec 06 '13 at 22:08

1 Answers1

0

Try to make the launchMode of that Activity B to SingleTask in your manifest file like this :

android:lanchMode="singleTask"

Your activity will not be called again.

Cyph3rCod3r
  • 1,978
  • 23
  • 33