1

I have a static ArrayList defined in my activity, being used by several fragments within it. This ArrayList is sometimes modified.

Is this bad practice? Should I be using bundles/SQLite instead?

Al Lelopath
  • 6,448
  • 13
  • 82
  • 139
Adam Arcaro
  • 451
  • 7
  • 19

2 Answers2

3

Yes static is always bad (you should avoid it whenever possible), because even if you dont have access to the Activity instance you can modify it like this SomeActivitiy.list.removeAll(); for example.

What I would suggest it the use of a DataProvider that contains your data and you just have to inject it in your fragments.

The SQLite option in the other hand should only be used when you have to persist the data, so you don't have to delete after using it.

Sofiane Daoud
  • 868
  • 9
  • 21
1

Consider using public field ArrayList and your fragments can use or modify it easily.

But, please read this first. Public field or Getter/Setter

phatnhse
  • 3,870
  • 2
  • 20
  • 29