Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

It would be correct to use the NavigationDrawer to open Activities, not fragments?

My application basically has one main activity. Within it there are three tabs, each with a fragment. Something similar to the layout of whatsapp.

To add more functionality to the application, I saw that the NavigationDrawer would be a good option. But because of my application running with a main activity with children fragments, I wonder if it would be a bad practice loading activities and not fragments, when the User clicking on any item NavigationDrawer.

Or does the best meneira would turn my MainActivity in a fragment? It would give me a great job ..

I would like to suggestions =)

like image 766
sThiago Avatar asked Jan 28 '26 01:01

sThiago


1 Answers

You can use the NavigationDrawer to open new activities. Basically just make each of the Activities have the same-looking Drawer and the user experience will be same as if you were replacing Fragments.

However, I would discourage this. I have been working with apps that mixed Fragments and Activities for the NavigationDrawer and the outcome was problematic, especially when it came to backtracking and saving state. It did work, but required hackfixing and some illogical code.

The best practice for the NavigationDrawer is to have one "container" activity which does little more that just exchanging Fragments in a FrameLayout it holds. The rest of the logic would be in the Fragments. This way the app is easily extendable and the backstack is handled by the platform.

like image 141
Kelevandos Avatar answered Jan 30 '26 18:01

Kelevandos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!