Difference between shared preference and sqlite

前端 未结 6 571
闹比i
闹比i 2020-12-06 01:59

I know this topic has been discussed before on Stack Overflow. But there are still some things that are not clear when I read previous posts about it. So here they are:

6条回答
  •  一个人的身影
    2020-12-06 02:41

    In the situation you described about you will lose the user name and password in both situations. The data is stored on the phone, when you uninstall the application, the data that some with it will also be lost. The user will have to re-enter this information.

    You can save the user name and pass in either the shared Preferences or a DB, that is personal preference. Just make sure you lock either down, i.e. don't share the DB or Shared Preferences that you keep this information in.

    As for the difference... shared Preferences should hold well... shared Preferences... here is an example:

    If I create an option to change the background color, I will store all available options in a DB that can be loaded into a adapter view for the user to choose from. But I will store the color that they have selected in the Shared Preferences. This way when the application load I can get the Shared Preference value of the background color that should be used.

提交回复
热议问题