Skip to content

GrenderG/Prefs

Repository files navigation

ko-fi

Prefs

Android Arsenal

Simple Android SharedPreferences wrapper.

Repository

Add this in your root build.gradle file (not your module build.gradle file):

allprojects {
	repositories {
		...
		maven { url "https://jitpack.io" }
	}
}

Dependency

Add this to your module's build.gradle file (make sure the version matches the JitPack badge above):

dependencies {
	...
	compile 'com.github.GrenderG:Prefs:1.3'
}

Usage

This is the basic usage, you can read values (specifying a default value or not) and write values like so:

  Prefs.with(yourContext).readInt(YOUR_KEY_VALUE);
  Prefs.with(yourContext).readInt(YOUR_KEY_VALUE, defaultValue);
  
  Prefs.with(yourContext).writeInt(YOUR_KEY_VALUE, valueToStore);

You can also specify a custom name for the preferences' name:

  Prefs.with(yourContext, "CUSTOM_NAME").readInt(YOUR_KEY_VALUE);

And force the re-instantiation of the Prefs instance:

  Prefs.with(yourContext, true).readInt(YOUR_KEY_VALUE);
  Prefs.with(yourContext, "CUSTOM_NAME", true).readInt(YOUR_KEY_VALUE);

You can also set and retrieve ordered String sets and unordered String sets.