Mocha
Mocha

Reputation: 33

Alternatives to static variables in Android

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?

Upvotes: 3

Views: 2409

Answers (3)

praveen ojha
praveen ojha

Reputation: 1

You can write an object to a file .Define class and fill it with required values at run time use objectwriter to save it

Upvotes: -1

Kris
Kris

Reputation: 566

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.

Upvotes: 3

mmaitlen
mmaitlen

Reputation: 822

Have you checked out Typed Array Resources?

Resource Types in the Android Dev Guide

Upvotes: 0

Related Questions