-1

I'm recently new to Android development and the idea of fragments in general. In ios I was able to create a drawer menu experience using SWRevealController, which leaves each page as it's own viewcontroller - roughly equivalent to an activity. These separate viewcontrollers were very clear on where to load data and were pretty self managing in their lifecycle.

Now in android a drawer activity has each page of the menu as a fragment - all belonging to the same activity. This leaves me with a few options:

  1. Have a mega-activity that knows how to load all the data for every possible page. This is potentially the easiest to do but the hardest to maintain.
  2. Have each fragment know how to load/display their own data. This seems ideal but has problems with reloading/duplicating data if done in onViewCreated. Additionally it makes the initial load of the drawer activity very slow, even when data loading is done in an async manner.
  3. What would be an easy to maintain approach for many drawer views that each need to make their own API call?
Nikhil
  • 3,711
  • 8
  • 32
  • 43
Eric H
  • 1,323
  • 3
  • 14
  • 29

1 Answers1

0

In android you have lots of life cycle methods compare to iOS.

You can create activities also for each view and extend BaseActivity which have drawer control. so this way you have drawer control in base class and you will get drawer in other activities also.

Secondly if you go with Fragment way you can use setUserVisibilityHint() or onViewCreated() method for call api or you can also use onResume() method with little bit checks. For more check this

Community
  • 1
  • 1
Wasim K. Memon
  • 5,979
  • 4
  • 40
  • 55
  • Yes, and additional to this use MVP pattern for decoupling view, and data layer. Code will be clear, testable, and easy to maintain. https://github.com/googlesamples/android-architecture – Mykhailo Sep 23 '16 at 18:50