Pref-DB
Android SharedPreferences alternative library.
Dependency
Add the JitPack repository to your build file
allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}
Add the dependency
dependencies {
implementation 'com.github.M-Fakhri:PrefDB:1.0' //Latest Release
}
How To Use
You need to initialize the Prefs
once your application starts, it's recommended to be in your Application
class, by using:
-
Initialization
Prefs.init(this) //should be inside OnCreate
Note: The initializing should be only once.
-
Store Data
To store new data you can use (Kotlin Indexed Access Operator), you can do it as the following:
//syntax: Prefs[Key] = Value
Prefs["Hello"] = "Hello" //set `String` value for key 'Hello'
Prefs["One"] = 1 //Set `Int` value for key 'One'
Prefs["0.9"] = 0.9f //Set `Float` value for key '0.9'
Prefs["Hello"] = "Hi" //Override key 'Hello' with new value
-
Retrieve Data
To retrieve stored data you can use getter methods, you can do it as the following:
Prefs.getString("Hello") //get `String` value for key 'Hello'
Prefs.getInt("One") //get `Int` value for key 'One'
Prefs.getFloat("0.9") //get `Float` value for key '0.9'
Prefs.getInt("Two",2) //get `Int` value for key 'Two' if not found return the default value which is 2.
Note: Currently supported data types are
Int
,Float
,Double
,String
andBoolean
.
License
Distributed under the Apache License 2.0. See the LICENSE file for details.