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:
- SQLite (with or without a content provider)
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.
精彩评论