A small and easy Shared Prefs library with more options : )
Add jitpack to your maven sources
allprojects { repositories { ... maven { url "https://jitpack.io" } } }
Add Censory as a dependency to your build.gradle
dependencies {
implementation 'com.github.KapilYadav-dev:Prefs.io:CURRENT_RELEASE'
}
- Initialization ( in application class )
- Use it 👨🏽💻
@Override
public void onCreate() {
super.onCreate();
// Initialize the Prefs class
SharedPrefs.init(this);
}
After initialization, you can use simple one-line methods to save and get those values from the shared preferences anywhere in your app, such as:
SharedPrefs.setString(key, string)
SharedPrefs.getString(key, defaultString")
SharedPrefs.setInteger(key, int)
SharedPrefs.getInteger(key, defaultInt)
SharedPrefs.setboolean(key, boolean)
SharedPrefs.getboolean(key, defaultBoolean)
It's a better practice to encrypt down your sharedPrefs so that it can't be altered by Root Piratess 🏴☠️
SharedPrefs.setString(key, string, encryptionKey)
// This will encrypt your String 🤐SharedPrefs.getString(key, defaultString, encryptionKey, encryptedText)
// This will decrypt down your encrypted String 😎
SharedPrefs.clear(context)