Reputation: 11
Actually, I have a doubt regarding SharedPreferences in android. I have started learning Android a few days back and I am creating a SignUp Page for now, for that, I have searched the internet and got some ideas and now I am using multiple shared preferences in my code which I am thinking it would be a bad practice. So, I just wanna know, what happens to the Application if we create multiple shared preferences in the code.
Upvotes: 1
Views: 708
Reputation: 1048
With the concept of consuming more memory we shouldn't use SharedPreference to store large amounts of data, Alwayas use SQL DB in android for that. Multiple sharedpreference is good because , you can store data seperate for different sections within the app if it doesn't need to be shared. Shared preference is just a xml file with key value pair. So if you store only simple key value pairs, its okay to have multiple shared preferences. But be logical in your decision, dont just do that because you can
Upvotes: 0
Reputation: 89
It is not bad practice at all. There is always a default shared preference. we can get default shared pref filename using .getDefaultSharedPreferences() method. you can get back up of any single shared pref file which is efficient.
Upvotes: 0
Reputation: 1214
This will just result in multiple SharedPrefenrences files (XML) in the data folder of your app. This is neither a problem nor a bad practice. If you have larger sets of structured data, consider using a database (e.g. SQLite/Room).
Upvotes: 2