Navigation Drawer and Fragments best practice - android

I am going to use Navigation Drawer in my app. I have read about most common approaches of building such apps, a lot of people suggest to change only framgent while selecting different items in navigation drawer. So instead of openning new activity it is better to change fragment of current activity ? Am I right ?
The problem is that I have main activity with two fragments now.
What is the best practice to follow in this case.
To open new activity on item click in navigation drawer ?
To use nested fragments, because my activity already has 2 fragments, so maybe to create some wrapper fragment to nest these two fragments or more if it will be another page.
Please suggest what is the best practice to implement this design pattern in my case.

Technically, the correct way is to change only the fragment while selecting different items in navigation drawer, which would be possible even with only two fragments. There is usually no reason to use nested fragments.
Obviously, there are many ways to do it, and from the UI perspective, there are many possible designs (Navigation Drawer, tabs, sliding pager, etc.)

Related

Using navigation drawer for multiple activities re-creates the drawer. How do I make it stay common?

I've created a base activity for navigation drawer and every other activity will extend this to display the drawer.
Doing this will re-create the drawer for each activity.
Is there any kind of workaround for this such that a common drawer is used across all the activities?
EDIT:
Source of what I've referred to do this:
Same Navigation Drawer in different Activities
I prefer using fragments instead of activities when dealing with a navigation drawer, this will both be more efficient and good looking.
A guide on how to do this can be found at:
fragment-navigation-drawer-guide
In short no, or at least: You should not do that.
Navigation drawers are usually to be used with fragments that you swap, they should not create new activities, since the drawer can not (or should not) be shared.
You should overthink your navigation, and use fragments instead where appropriate. Following the design guidelines, again, navigation drawers should be the top most navigation, and no other activities should have one either.
The answer on how to use a common drawer would hence be to use an activity with the drawer managing different fragments.
If you absolutely must, you can detach the navigation drawer view from the layout, keep the reference some place, then reuse the same view in another activity. This is really dirty and as mentioned, you should not do this.

Applying navigation drawer throughout the app in Android?

I had an app which was developed 2 years back, now I want to add navigation drawer to that app, but the problem is in that app there are 15 Activities, so do I need to apply the Navigation drawer for all 15 Activities? or is there best way to implement this.?
The navigation drawer items are common for whole app.
Can anyone suggest me the best way to implement this.
A way you can do it, since Navigation Drawers are just list fragments, is create a list fragment and recall that same fragment in all the activities that you want it in. You can do this using the XML Layout Editor to place the fragment in the layout.
Having so many activities, however, makes it a lot of work (especially if your app is designed for multiple sizes and each activity has a layout).

Need clarification on how the native Navigation Drawer works with Fragments

I'm used to using a 3rd party library for implementing a navigation drawer (sliding menu) in Android, but I want to use the native version from now. I went through the tutorial (http://developer.android.com/training/implementing-navigation/nav-drawer.html) which is pretty straight forward.
I typically extend the 3rd party navigation drawer to each activity by defining the configuration in a base class. The new nav drawer, however, swaps fragments in and out, which my research indicates is the standard way of managing your displays.
This seems fine, but my app has a fairly complex hierarchy of pages and navigation. Like most apps, it contains more fragments than just the ones in the menu.
So if I have 3 nav drawer items for fragments A, B, and C, and I can only load fragment D from fragment C, do I handle that navigation logic in the activity where I configure the nav drawer? It seems like kind of a nightmare to have one container to swap out an indefinite number of fragments, especially if the work flow is deep.
From what I can gather on Stack, there seem to be a lot of people who are familiar with extending a 3rd party drawer in each Activity, but when they switch over to the native version there is confusion.
So to summarize, I understand the fragment swapping aspect of the navigation. I just don't understand how the rest of the work flow navigation would work, say if I had several detail screens below a nav item fragment. If anyone can give me some hints on how best to approach this scenario, maybe I can experiment and post some code for future readers.
For navigation in Android there is always one thing you have to remember:
If you stay on the same level of the navigation hierarchy, for
example when swiping through pages, you use Fragments.
When you move up and down in the navigation hierarchy, for example
going to a detail view, you would start a new Activity and displayed the
Fragment with the detail content in it.
A NavigationDrawer is used for top level navigation in your app to quickly navigate between different parts of your app. It's kind of like a main menu. With that in mind you need to determine if a NavigationDrawer makes sense in your app. It's all about how the user should navigate through the content. If there is just one path for the user to follow for example if you start out with just one screen and from then on the user can just go deeper and deeper in the navigation hierarchy from one detail view to the next than a NavigationDrawer does not make much sense. But if there are multiple paths the user can take that lead into different, independent parts of your app without one dedicated start screen on which everything else depends than a NavigationDrawer sounds pretty reasonable.
You can look at Google apps like Gmail, Drive or Google+ to see how a NavigationDrawer is supposed to be used.

Best practices on Navigation Drawer use

I was reading about Navigation Drawer and it was not until now that I came into this question: If my top views are going to be accessible through the Navigation Drawer, should I code each of them as Fragments or as Activities?
I want to know the way it was intended to be used, with Fragments or with Activities
The best way is to use Fragments.
When you click on an item, you should always replace the Fragment of your Main Activity without adding the elements in the Back Stack. This will create a seamless dynamic navigation instead of launching new activities and managing the drawer into them.
Here are some references
Google's design guidelines
Google's development guidelines

Android Navigation Drawer Design

I have an existing application that has about 25 activities that are navigated to from a "dashboard". I would like to switch and start using the Navigation drawer and fragments. I have gone thru the Nav Drawer design pages online and the example app. My question is what is the best way to convert (structure) my app to fit the Nav Drawer pattern. If I switch my activities to be fragments and use a main activity to replace each fragment as navigation happens, but not sure if that is good b/c for a tablet layout, I might want multiple fragments on my view and not sure if this will limit me. If I go with the other direction I was thinking, keep all my activities and just switch the necessary ones to fragments for tablets but I would need each activity to create the navigation drawer (I think ?) which in my case the drawer is dynamic based on server data. Any suggestions would be great.
Thanks
Brandon
Navigation drawer has to be created for each activity, although you could inherit Activity and create a parent class that handles navigation drawer specific code if code duplication is a concern.
Using a drawer does not limit you to use one fragment per screen, just listen to onClick in drawer and initiate as many fragment transactions as you need.
When it comes to structuring your app, there is no universal advice, I would recommend you to watch Google I/O 2013 talk - Structure in Android App Design. Navigation Drawer is kind of the main theme of the talk.

Categories

Resources