SCENARIO
I have a class that uses a user-defined list of queries. The list of requests is stored in SharedPreferences. The dilemma I came across is whether to store an instance of the query list or read from SharedPreferences every time a query list is required (which is very common).
Also, Gson is not used to deserialize an object.
The code is as follows:
public List<PrayerTimesCalculator.Time> getDefaultRequestList() { if (mRequestList != null) return mRequestList; // Try getting request list from preferences; Gson gson = new Gson(); String json = mSharedPref.getString(KEY_PREF_REQUEST_LIST, null); Type listType = new TypeToken<List<Time>>() { }.getType(); mRequestList = gson.fromJson(json, listType); if (mRequestList != null) return mRequestList; // Create default list; mRequestList = Arrays.asList( Time.DAWN, Time.MORNING, Time.AFTERNOON, Time.EVENING, Time.MID_NIGHT); return mRequestList; }
TARGET
My concern is that if I keep an instance of the query list and there are several instances of this class, updating the query list in one instance of the class will not be reflected in the rest of the instances until they are recreated.
, SharedPreferences, , .
(1) , SharedPreferences ? (2) ?
, , .
-, - SharedPreferences . SharedPreferences " ".
SharedPreferences
-, , DAO ( ). SharedPreferences - . , . , ( , ), , "" "". , . , .. ( SharedPreferences).
Cursor DAO. , , , , , .
Cursor
, , , Content Provider. , / , ( ). , .
, , , SharedPreferences . - - , .