0

I have an Android application that uses 1 navigation drawer activity with several Fragments. The activity fetches JSONObjects from a REST API and converts them to ArrayLists of custom objects.

These custom ArrayLists are used throughout several fragments, some of them being modified and some of them only used for display. My app currently has these ArrayLists as static objects and imports them into the necessary Fragments, but I'm aware that this is probably not the best way to approach this.

Should I keep using static ArrayLists or should I pass the ArrayLists in bundles when I create the fragments? Of course, any better suggestion would be greatly appreciated as well.

Adam Arcaro
  • 451
  • 7
  • 19

1 Answers1

0

You should use bundles because getting arraylist everytime from REST api can take time and there is no need to get data from REST api again and again when you can pass them. Accessing REST api without the need of it is bad pratice. And also it would save you the time of writing same code in every fragment.

  • Actually, I'm only using the REST API once (with the activity's onCreate). It's simply a matter of referencing this newly formed ArrayList in the fragments – Adam Arcaro Jun 28 '17 at 18:01
  • Okay then you should use static arraylist because bundles have limit to pass data, bundle would create problem if the data is too large. Bundle limit is 500kb as mentioned here [link](https://stackoverflow.com/questions/8552514/is-there-some-limits-in-android-bundle) – Roshan Baig Jun 28 '17 at 18:35