I am developing my first android Application and hoping to get some tips here.
I am getting a JSONObject
from an url which then will be parsed in an ArrayList<MyObject>
. The list will be used in multiple tabs and be filtered as needed for the tabs. The objects within these list can be modified by the user and the changes should be synchronized with the lists.
So, to speed up loading time I have created a class DataHolder
as a singleton which contains 7 arraylist, based from the one JSONObject
in different sorting order and filter criterion. The objects in these lists are references from the original list. Populating the lists works fine.
The lists will be used in different fragments and activities.
Now the problem: the second activity contains tabs with fragments. After initializing the fragment... all arraylists in the DataHolder
counts 0! I have to save the JSONObject
in SharedPreferences
and populate it again to get the List
. I can't load the url again because it is slowing down the app to much and using SharedPreferences
is not an option (I think) because of the need to synchronized the Lists
. I have read that using static variables is not the optimal solution, but it seems to be the easiest way :(
What can I do to solve this problem? Should I use Parcelable Objects
and always pass the Lists
around? Or maybe use SQLite
? Or are there other approaches?