gondai yosuke
gondai yosuke

Reputation: 609

Save list content for next use properly

As you see on app like facebook, twitter, etc you have list of content in home page. if you close the app then open it again, you still have those content without load again from server.

currently i use this code to save all value in my app

SPref.setPref(getActivity(), Config.USER_ID, lb.userId);
SPref.setPref(getActivity(), Config.USER_NAME, lb.name);
SPref.setPref(getActivity(), Config.USER_EMAIL, lb.email);

its just save a string or a an int value not a list. i used saving data at local device with sqlite and a file for my other project. in this case in my new project, i want to make sure which way is better for saving list value.

by the way, i use SharedPreferences because someone told me its faster.

Upvotes: 1

Views: 54

Answers (2)

Akash Bangad
Akash Bangad

Reputation: 4

Shared Preferences certainly are very fast, but those aren't meant to be stored with a huge data set, As the name suggest those are meant to store the preference data of the app in a key value pair for example

  1. setting the sound on/off
  2. setting the logged in status
  3. setting the day/night theme for the app.

In the above example whenever user changes a setting you can just store it in SP, and use it next time to make any decisions

For Larger data set, you have to use SQL lite https://developer.android.com/training/basics/data-storage/databases.html

Or Realm DB(Third party library) https://realm.io/

Upvotes: 0

Gaurav
Gaurav

Reputation: 3763

shared preference

is only to store KEY , VALUE pair, So you can store here small amount of data like username , some flags etc.

To store your normal contents like here you want to store list.

Use SQLite for this is the list will not frequently going to changed, or it will going to modify then use Cache.

Please follow this links for better understanding
https://developer.android.com/guide/topics/data/data-storage.html

https://developer.android.com/reference/android/util/LruCache.html

Upvotes: 2

Related Questions