I am using static Arrays and HashMaps to store some values in my AppWidgetProvider class. But they are becoming null when the process dies, so the widget does not work anymore. Are there any alternatives to using static members to store data for an AppWidgetProvider in Android?
Unfortunately TypedArray does not allow storing values at run time, which is what I'm looking for.
Mocha
2010-06-17 19:21:39
Any other ideas?
Mocha
2010-06-17 21:24:22
if you need to store a small amount of data, i'd use SharedPreferences, anything running within the context of the Application will be able to access the selected info...if you need more storage then that, I'd look at using an Sqlite db and store your info in tables, but that may be to heavy weight. By using the SharedPreferences, you could store a well known formatted string, or maybe the string equivalent of a JSONObject/JSONArray, then you can use the JSONObject/JSONArray object to parse the data back into something for the app to use.
mmaitlen
2010-06-17 21:32:42
+1
A:
The "correct" way to do what you're doing (I believe) would be SharedPreferences. The Android dev guide has a great page on the different methods of Data Storage in Android. Also, try not to use too many static values; perhaps what you're doing would be better accomplished with singleton classes, though, from the question, it's hard to tell what you're using them for.
Kris
2010-06-17 22:08:52