Switch Fragments or new Activities?

Search This thread

Arret

Member
Nov 11, 2011
6
0
Hi guys,

I am new to android app development and have started creating my first simple app in Android Studio. So far everything is working, I have a drawer menu, the user can switch between screens, back button in the activity bar etc.

As I learned the basics with tutorials on the internet I could not find an answer to one question.
Some tutorials suggest/show that you should switch the Fragments when navigating to another screens when selecting an item from the drawer. So I create Fragments and when someone clicks on a button I change the fragment.
However there are also Activities, and I can make the same thing work by creating new Activities for each screen the user should see.

I cannot really see a clear benefit from one method compared to the other. Switching Fragments may be less work but may also get more messy.
What is in general the best practice here? Create Fragments for each menu item and switch the Fragments or create a new Activity for each menu item?

thanks
Arret
 

js2892

Senior Member
Jul 28, 2012
660
387
Bangalore
Hi guys,

I am new to android app development and have started creating my first simple app in Android Studio. So far everything is working, I have a drawer menu, the user can switch between screens, back button in the activity bar etc.

As I learned the basics with tutorials on the internet I could not find an answer to one question.
Some tutorials suggest/show that you should switch the Fragments when navigating to another screens when selecting an item from the drawer. So I create Fragments and when someone clicks on a button I change the fragment.
However there are also Activities, and I can make the same thing work by creating new Activities for each screen the user should see.

I cannot really see a clear benefit from one method compared to the other. Switching Fragments may be less work but may also get more messy.
What is in general the best practice here? Create Fragments for each menu item and switch the Fragments or create a new Activity for each menu item?

thanks
Arret

When using a navigation drawer fragments is the best technique.
All your fragments are housed inside one activity which will allow navigation through drawer. If you start new activity on item select, you will lose the navigation drawer(because new activity will not have the navigation drawer). Even if you add a navigation drawer in all activities you create, the flow itself will be a mess.
Also using many activities can make app look heavy. Fragments on the other hand are very light and provide good layout options(search coordinator layout).
 
  • Like
Reactions: Arret

arnavrp

Member
Dec 21, 2016
13
0
Fragments vs Activity

It depends on the app that your working on.
With activity, it is very hard to achieve re-usability of components. Where as fragments can be used to create reusable modules.
If you see in modules in your activity, then go for one activity and fragment each module.
It may not be strictly one activity per app.
 

Top Liked Posts

  • There are no posts matching your filters.
  • 1
    Hi guys,

    I am new to android app development and have started creating my first simple app in Android Studio. So far everything is working, I have a drawer menu, the user can switch between screens, back button in the activity bar etc.

    As I learned the basics with tutorials on the internet I could not find an answer to one question.
    Some tutorials suggest/show that you should switch the Fragments when navigating to another screens when selecting an item from the drawer. So I create Fragments and when someone clicks on a button I change the fragment.
    However there are also Activities, and I can make the same thing work by creating new Activities for each screen the user should see.

    I cannot really see a clear benefit from one method compared to the other. Switching Fragments may be less work but may also get more messy.
    What is in general the best practice here? Create Fragments for each menu item and switch the Fragments or create a new Activity for each menu item?

    thanks
    Arret

    When using a navigation drawer fragments is the best technique.
    All your fragments are housed inside one activity which will allow navigation through drawer. If you start new activity on item select, you will lose the navigation drawer(because new activity will not have the navigation drawer). Even if you add a navigation drawer in all activities you create, the flow itself will be a mess.
    Also using many activities can make app look heavy. Fragments on the other hand are very light and provide good layout options(search coordinator layout).
Our Apps
Get our official app!
The best way to access XDA on your phone
Nav Gestures
Add swipe gestures to any Android
One Handed Mode
Eases uses one hand with your phone