https://github.com/grenderg/prefs
Simple Android SharedPreferences wrapper.
https://github.com/grenderg/prefs
android android-wrapper sharedpreferences
Last synced: about 1 year ago
JSON representation
Simple Android SharedPreferences wrapper.
- Host: GitHub
- URL: https://github.com/grenderg/prefs
- Owner: GrenderG
- License: gpl-3.0
- Created: 2016-05-07T13:29:32.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2020-04-11T13:42:42.000Z (about 6 years ago)
- Last Synced: 2025-03-27T07:21:19.246Z (about 1 year ago)
- Topics: android, android-wrapper, sharedpreferences
- Language: Java
- Size: 126 KB
- Stars: 129
- Watchers: 6
- Forks: 26
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://ko-fi.com/R6R21LO82)
# Prefs
[](https://jitpack.io/#GrenderG/Prefs) [](https://android-arsenal.com/details/1/3570)
Simple Android `SharedPreferences` wrapper.
Repository
--
Add this in your root `build.gradle` file (**not** your module `build.gradle` file):
```gradle
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):
```gradle
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:
``` java
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:
``` java
Prefs.with(yourContext, "CUSTOM_NAME").readInt(YOUR_KEY_VALUE);
```
And force the re-instantiation of the Prefs instance:
``` java
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`.