Saving state with BroadcastReceiver
I have a widget and I want to save its state when it's being clicked.
Curre开发者_运维知识库ntly I'm saving the state with SharedPreferences.
This works but it is relatively slow to commit updates to the preferences.
Are there any better solutions?
Thanks.
I have a widget and I want to save its state when it's being clicked.
If by "widget" you mean "widget", this makes no sense. At most, a widget should be communicating with its hosting activity. The activity can save its state at appropriate times using appropriate means.
If by "widget" you mean "app widget", this makes more sense.
Currently I'm saving the state with SharedPreferences.
This works but it is relatively slow to commit updates to the preferences.
Are there any better solutions?
All writes to flash are slow, by flash's nature. Where possible, committing SharedPreferences
should be done in the background. On Android 2.3 and higher, you have a new apply()
method that does that automatically.
精彩评论