-
Notifications
You must be signed in to change notification settings - Fork 8
Home
Hendra Permana edited this page May 6, 2017
·
3 revisions
Take a look a full example here : https://github.com/hynra/GSON-SharedPreferences/blob/master/example.md
- on your
build.gradle
root :
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
- Add dependency
dependencies {
compile 'com.github.hynra:GSON-SharedPreferences:1.1'
}
Prepare your (Gson) Object via generator. For example, you can generate your obect from JSON Object
to (Gson) object
with online tool like http://www.jsonschema2pojo.org/, then add generated object(s) to your project.
GSONSharedPreferences gsonSharedPreferences;
context = this;
gsonSharedPreferences = new GSONSharedPreferences(context);
it will save in PreferenceManager.getDefaultSharedPreferences()
.
GSONSharedPreferences gsonSharedPreferences;
context = this;
String prefName = "whatever"
gsonSharedPreferences = new GSONSharedPreferences(context, prefName);
it will use Context.MODE_PRIVATE
mode.
GSONSharedPreferences gsonSharedPreferences;
context = this;
String prefName = "whatever"
int mode = Context.MODE_PRIVATE;
gsonSharedPreferences = new GSONSharedPreferences(context, prefName, mode);