开发者

What do I use preference or sqlite database for my application settings screen

开发者 https://www.devze.com 2023-02-21 13:33 出处:网络
Please excuse me if this is a very novice question, but I am little confused. I have a settings screen in my application, where there are check box or radio button option and spinner option. user has

Please excuse me if this is a very novice question, but I am little confused. I have a settings screen in my application, where there are check box or radio button option and spinner option. user has to select one and my application will be updated with开发者_高级运维 the saved settings option. Now I believe I can do the same with sqlite database but looks like preferences is used for such kind of scenarios only. How good it will be to use preferences and not sqlite database. I am not sure which way I should head.

Please someone explain. Thanks in advance.


Go with SharedPreferences. It's a lightweight key/value store that's easy to use for primitive types.

A SQLite database is more useful if you have relational data, but it's more ceremony than you need for preferences. You'll need to write SQL queries to retrieve and update variables, manage your schema (e.g., upgrade the database if you decide to add new preferences), manage your database by opening and closing it with SqlDatabaseHelper, etc.

In short, a SQLite database is a lot of overhead you won't need.


SharedPreferences is good for non-structured data. It's quite easy to use; with SQLiteDatabase you would end up writing quite a bit of code while never taking advantage of the core competencies of sqlite3, such as indexing, sorting and joins.

0

精彩评论

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

关注公众号