1


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

Metal
  • 13
  • 6
  • What do you mean by common drawer?. You can check the google io schedule app on github. It has the same drawer for all activities. https://github.com/google/iosched – Raghunandan Mar 06 '16 at 11:20
  • 1
    Common drawer meaning, all activities access the same drawer rather than a new instance of the drawer. – Metal Mar 06 '16 at 11:23

2 Answers2

1

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

Julian Kroné
  • 179
  • 1
  • 13
  • One of the reasons I use activities across is to be able to handle a notification inside a service. This got very complicated while I was using Fragments. The notification used to get destroyed. – Metal Mar 06 '16 at 11:28
  • I know this was a while ago but thankyou so much for that guide! – gogobebe2 May 13 '16 at 20:08
0

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.

David Medenjak
  • 33,993
  • 14
  • 106
  • 134