This might be more of a pure CS question, but I am having a trouble understanding how SHARED PREFERENCES
works in the context of saving and resuming an application when saving Objects in GSON
Format.
When you save GSON to Shared Preferences, is the GSON Strings themselves the only things that are saved (ie. the objects are lost)?
And if this is true, when you resume the application, how are the objects retrieved ?
Are they re-instantiated with the GSON data or does the GSON data store a location in memory within itself, or is the Shared Preferences the overall location stored in memory?
For example,
Context
TaskManager.java
class TaskManager {
String managerName;
LinkedList<Task> taskList = new LinkedList<Task>();
}
Task.java
class Task {
String taskName;
int Time;
}
FooBarActivity.java
class FooBarActivity extends Activity {
TaskManager manager = new TaskManager("manager1")
Task newTask = new Task("task1");
manager.taskList.add(newTask);
SharedPreferences mPrefs = getPreferences(MODE_PRIVATE);
SharedPreferences.Editor prefsEditor = mPrefs.edit();
Gson gson = new Gson();
String json = gson.toJson(manager);
prefsEditor.putString("manager", json);
prefsEditor.commit();
}
manager object JSON:
{"manager":[
{"name":"manager1"
"taskList":"[task1]"}
]}
Is that task1 element of the List:
- contain all of the instance variables of the original Task object (ie. it's name/time?)
- OR Store a location in memory (say @40E1, idk)
- OR is it just a plain string which I have to create a new object and use it as data to instantiate?