6

I have a NavigationView used as a slide-in menu. Each of that menu items is a use case itself, therefore I tend to using activities containing different fragments.

But nearly every example of NavigationView/NavigationDrawer uses fragments, so I don't know what to use here.

I thought different use cases should be "encapsulated" in own activities, therefore I don't really understand why Navigation[View/Drawer] uses fragments. And that leads me to my question: for a Navigation[View/Drawer] containing completely separate use cases - should I link to activities or fragments?

swalkner
  • 16,679
  • 31
  • 123
  • 210
  • navigation drawer embeds in Activity and all the menu items are (most of the time) fragments. when you click an item in drawer it fetches the fragment and replaces it with the current. If you use activities for each menu item you have to put `navigation drawer` in each of that `activities` – Murtaza Khursheed Hussain Aug 18 '15 at 08:06
  • 1
    @MurtazaKhursheedHussain not a fact, he could have a base activity that always has the navigation view. – Kosh Aug 18 '15 at 08:40
  • @k0sh That's just redundant. And swalkner, every example out there uses fragments for a reason. That's what recommended by Android developer team them selves. IMO you just need to get rid of the strong idea that you have about encapsulating a use case in it's own activity and think a little freely and understand the benefits of using fragments. – JanithaR Aug 18 '15 at 09:05
  • @k0sh yes not a fact but not recommended, until and unless you want it – Murtaza Khursheed Hussain Aug 18 '15 at 09:25

2 Answers2

1

I posted a similar question

I have created around 4-5 apps with mid-big size project. I used Fragments for Navigation Menu clicks and had to manage lots of Lifecycle events and Memory Leaks and shit stuff. The Performance degrades and app becomes slow.

Then in one of the app I Used Activities for each Navigation menu clicks, treating it separate Entity/Module. This Activity would then use fragments if they had child views.

Doing so I had a great app, less trouble and I could concentrate on Business Logic rather than maintaining fragments.

Although Google recommends Fragments, But I never liked them, they always put me in trouble and handling them is a mess.

In my current Project I have created a BaseActivity implementing Navigation and all the other Activity extend it.

Community
  • 1
  • 1
Rinav
  • 2,527
  • 8
  • 33
  • 55
0

the NavigationDrawer and the contents are all just Views inside the Activity view hierarchy.

The use it of fragments is usually shown in tutorials because you can encapsulate each item inside a fragment, and fragments is the usual Google advice, even though they're a pain in the ass and have horrible drawbacks regarding animation.

But the direct answer to your question is: It's all just a matter of structure and organisation and it really does not matter how you do it, because in the end they're all just views in the Activity view hierarchy.

  • You can "manually" inflate views and put in the content area.
  • You use fragments to separate the views and logic and their own container.
  • You can use activities with different content and the same NavigationDrawer.
Budius
  • 39,391
  • 16
  • 102
  • 144