开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜