views:

198

answers:

2

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?

A: 

Have you checked out Typed Array Resources?

Resource Types in the Android Dev Guide

mmaitlen
Unfortunately TypedArray does not allow storing values at run time, which is what I'm looking for.
Mocha
Any other ideas?
Mocha
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
+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