Friday, June 10, 2016

Back Navigating with Android Fragments and Navigation Drawer


I'm developing a fairly complex Android application (used for a Home Automation system) which is basically a One Activity - Multiple Fragments Application.


The Navigation in the application primarily consists of a Navigation Drawer. It has 6 Different Categories which we can name A..F. These categories can have their own Navigation Hierarchies, but I have chosen to not use an explicit Back Button in when digging down the a hierachy - Rather, I show the Hamburger Icon always. This lets the user access the Navigation Drawer at all times and relies on the user using the Hardware Back button for navigating back to the previous Fragment.


Now, I guess some of you might say this is bad practice (and I would listen if you told me how to do it instead) but I still have a problem I would like to solve without changing the Architecture, presented in the following use case:


Use case:



  • The User opens the Activity and arrives to Fragment A.

  • The User uses Drawer to go to B


  • The User navigates from B to Bb to Bc (Sub views of B)

  • The User uses Drawer to go to C

  • The User uses Drawer to go to B

  • The User navigates from B to Bb to Bc (The same sub views as before)

  • The User goes through the entire Back Stack using the Back Button


What happens is of couse that the user sees [Bc, Bb, B, C, Bc, Bb, B, A]


Now I generally think that the behaviour is correct, but will it result in a bad user experiecnce to see Views more than one time when using the Back button? If so, how can the problem be solved?



Answer



I am in a similar situation as you, and I completely see your point.



In my case when I switch section with the navigation drawer, a new fragment is presented. When the user navigates in the section the fragment is replaced, so the back stack grows. In order to avoid the kind of issues you are encountering, when the user goes to another section I save the state of all the fragments in the back stack, and then clear the back stack (otherwise the user will be able to go back anyway), and then eventually restore it when he goes back to the same section.


I have to admit that I think my code is not the nicest, but for the moment it's the only solution I have found to this issue. To be sincere, I am kinda surprised that there are not "out of the box" solutions to this kind of back stack switch with the navigation drawer.


No comments:

Post a Comment

technique - How credible is wikipedia?

I understand that this question relates more to wikipedia than it does writing but... If I was going to use wikipedia for a source for a res...