MaTTo
MaTTo

Reputation: 2396

Navigation drawer with fragments or activities?

I know it was answered before but I am still confused, if I should use fragments or activities for navigation drawer.

What is better practice? Google does not say anything about it and I am a little dissapointed.

Also, if I create a new project from Android studio with navigation drawer template, what I get is one single activity and one single fragment, but there is also separate fragment for navigation drawer and inside it, there is an interface and above it is a comment saying: "Callbacks interface that all activities using this fragment must implement.". It confuses me even more because I think I should use activities, but I am not sure.

Upvotes: 2

Views: 925

Answers (2)

Martin Pfeffer
Martin Pfeffer

Reputation: 12627

Keep in mind that a nav-drawer can be used for different user interactions. By the common usage as a navigation element, you will implement it by fragment(s). In this approach the drawer is placed on the left side. An other approach can be to perform actions by pressing an drawer entry. In this situation you wont replace any fragments and only implement the drawer to the activities which should be able to perform this particular interaction (maybe: "send contact per a email")

Upvotes: 1

Hulk
Hulk

Reputation: 237

I will keep it very simple: When you switch between activities , user has a bit of feeling as if we are taking him to another view(as if we are making him switch somewhere and the whole view is changed with a sudden blink) but when you do same stuff in one activity and changing views through fragment, it is very smooth. Moreover passing data from one fragment to other is very easy and less expensive as android says activity transactions are expensive.

Yet many times it depends on your requirement.

Upvotes: 2

Related Questions