0

I have an android app where I want to have different functionalities, like a search function, a history, user defined lists,... Each of these functionalities is accessible via NavigationDrawer, and I want to contain a ViewPager to allow navigation in Tabs in each of those specific functionalities. Finally, when I switch between functions via NavDrawer I want my app to restore the state the corresponding function was in the last time it was used.

I'm puzzled about the best way to implement this. Currently, I'm using one Activity, which contains the logic for functionality navigation, and saving and restoring of current state of each fragment. I'm using one ViewPagerAdapter to hold information about current active fragments.

Another possible approach would be to make an Activity for each top-level functionality, and then implement the Fragments as needed. A third approach I can think of would be still using only one Activity, but different ViewPagerAdapter to hold the state information of each top-level function.

I'm really not sure which is the best way to go here, and I would like to settle on one of those possible options before going further, but I can't really find any useful information on the net. Are there any Best Practices known for my given scenario, or is this really just an opinion based topic?

Edit: No duplicate of Difference between Activity and FragmentActivity because I'm not even tackling the issue of support library vs. native

Edit2: I think it should be also possible by using nested fragments, i.e. having a fragment which hold my ViewPager where I could add my fragments for that function. But I really would prefer not using nested fragments at all.

Benjamin Scharbau
  • 2,028
  • 1
  • 16
  • 33
  • Somewhat opinion-based, because you're also missing out on the `custom viewgroups / custom views` approach with Mortar/Flow https://corner.squareup.com/2014/10/advocating-against-android-fragments.html ) – EpicPandaForce Sep 11 '15 at 08:11
  • 1
    possible duplicate of [Difference between Activity and FragmentActivity](http://stackoverflow.com/questions/10477997/difference-between-activity-and-fragmentactivity) – Jaykumar Donga Sep 11 '15 at 08:18

1 Answers1

0

A Fragment is best thought of as "a group of reusable interface elements". So if you can think of reusable elements across the activities (or a single activity when it's recreated) then you use fragments.

Activity is best thought of as "a single screen with UI". So then..

Alexander Kulyakhtin
  • 47,782
  • 38
  • 107
  • 158