开发者

Widget data: ContentProvider or SharedPreferences?

I'm developing a widget, it needs both to store data local to the widget instance and global to all widgets (cache and common data). Currently i'm using a PreferenceActivity setting its sharedpreference file to MYAPPNAME+WIDGETID, then i store common data (4/5 vars) in MYAPPNAME prefs.

I saw a lot of开发者_如何学C examples on the net using ContentProvider for this purpose, is there any advantage? Is it faster or different in some way to sharedpreferences? Sorry but its really not clear.


My recommendation would be, in order of, er, preference:

  1. SQLite (with or without a content provider)
  2. SharedPreferences

The reason? Transactions. SharedPreferences are just stored in an XML file. SQLite is transactional. I trust SQLite for data integrity a bit more than an XML file.

However, you do not need a content provider to manage data in SQLite, though you can use one if you wish.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜