Android Studio - SharedPreference -Store and retrieve data

+1 hs clover · January 13, 2016
I wanted to store data in shared references. There are 10 different items with different price and details.

User will select to add to cart. If I were to retrieve the information of items added and display the total price, items in cart with highest and lowest price.

Is it better to stored by
(i) each item with different class of sharedpreference,
(ii) sharedpreference with class of name, price, detail
or any other ways?

Post a Reply


Oldest  Newest  Rating
0 David Frenzel · January 17, 2016
None of them are for storing them. They just represent ways of how you display/handle your settings window. Either by using an activity (which is not recommended by Google anymore) or a fragment (which is recommended by Google!). 
0 hs clover · January 14, 2016
.what about preferenceActivity and preferencefragment to store the integer input of price? is it suitable?
0 Gary Whitney · January 13, 2016
Disclaimer: My post is not a definitive answer.

Shared Preferences are for storing data that will be used between runs of the application:
You can use it for other purposes but that is what it is for.

As far as I can tell, it only has methods for getting primitives and Strings NOT objects.
So you are going to be storing 10 floats and at least 20 strings.

If you just want to store selections while the app is running then I suggest:
* create a class about items
* and create objects to represent the items
* store the items in an arrayList

Another option is SQLite but I wouldn't bother for 10 items.
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator