CopyPastor

Detecting plagiarism made easy.

Score: 1.9225985324894344; Reported for: String similarity, Exact paragraph match Open both answers

Possible Plagiarism

Plagiarized on 2013-11-19
by Sandeep

Original Post

Original - Posted on 2011-10-27
by Drejc



            
Present in both answers; Present only in the new answer; Present only in the old answer;

I found the easiest solution to store and retrieve a list of items from SharedPreferences is to simply serialize / deserilaize the array into / from JSON and store it into a string setting.
**Gson** comes really handy doing it.
READ:
SharedPreferences prefs = context.getSharedPreferences("settings", Context.MODE_PRIVATE); String value = prefs.getString("list", null); GsonBuilder gsonb = new GsonBuilder(); Gson gson = gsonb.create(); MyObject[] list = gson.fromJson(value, MyObject[].class);
WRITE:
String value = gson.toJson(list); SharedPreferences prefs = context.getSharedPreferences("settings", Context.MODE_PRIVATE); Editor e = prefs.edit(); e.putString("list", value); e.commit();
I found the easiest solution to store and retrieve a list of items from SharedPreferences is to simply serialize / deserilaize the array into / from JSON and store it into a string setting.
Gson comes really handy doing it.
READ:
SharedPreferences prefs = context.getSharedPreferences("settings", Context.MODE_PRIVATE); String value = prefs.getString("list", null); GsonBuilder gsonb = new GsonBuilder(); Gson gson = gsonb.create(); MyObject[] list = gson.fromJson(value, MyObject[].class);
WRITE:
String value = gson.toJson(list); SharedPreferences prefs = context.getSharedPreferences("settings", Context.MODE_PRIVATE); Editor e = prefs.edit(); e.putString("list", value); e.commit();

        
Present in both answers; Present only in the new answer; Present only in the old answer;