I have the following List:
List<Map<String, String>> items = new ArrayList<Map<String, String>>();
It’s populated with data on the load of my app. I need to use it throughout my entire app, on most Activities and Fragments, with data both being read and being modified.
What is the best and simplest way to make this global without too much complexity?
Note: For reasons that are too much to explain on Stack Overflow, this much be used a List and not as a custom Object with properties.
other posts are missing the point. of course he can store the list as an instance member and access it with getters and setters, but what object owns the member?
you can use statics as has been suggested, but there’s a better way … just hang it off of your application class. create a class that extends
Application, and add the instance there,configure the application class into your manifest,
now, in your activities, or services, just do this,
from your fragments, do this,
and the nice thing is that this object has the same lifecycle as your application. it exists while any part of your application is active, and gets GC’d along with your application.