Is it Possible to Use PreferenceActivity with SQLite instead of res/xml?

后端 未结 1 972
长发绾君心
长发绾君心 2020-12-18 11:14

The beauty of PreferenceActivity is its tight integration with Android\'s res/xml. All you need to do achieve the magic of self-managed preference reading/savin

相关标签:
1条回答
  • 2020-12-18 11:51

    Interesting question.

    Short answer: AFAIK, there is no way you can use SQLite with PreferenceActivity without doing significant customization as it is not designed to work in that manner.

    The point here is why do you actually need SQLite for managing preferences? SQLite should as-a-rule never be used for lesser data that can be managed without requiring relational structure. For istance, it makes perfect sense to use SQLite when you have multiple instances of similar data like rows in a table.

    In case of Preferences, I cannot figure any such instances. Moreover SQLite hits the performance of the application compared to SP. Make your choices wisely.

    Update: In case you have multiple Preferences like in the question mentioned above you can use a combination of SQLite and SP. You cannot replace SP with SQLite for sure. What can be done though is that you need to keep a unique key which would become the primary key of the table and then in onPause of the PreferenceActivity you need to fire insert/update query in the SQLite table. You need to be careful and ensure correct SP are displayed and hence in onResume of PreferenceActivity you need to be able to fire fetch query with the unique key and set the SP accordingly.

    0 讨论(0)
提交回复
热议问题