Skip to content

An easy Shared Prefs library with more options : )

Notifications You must be signed in to change notification settings

KapilYadav-dev/Prefs.io

Repository files navigation

Prefs.io

A small and easy Shared Prefs library with more options : )

Implementation

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'
}

Usage

  1. Initialization ( in application class )
  2. Use it 👨🏽‍💻

Initialization

@Override
public void onCreate() {
    super.onCreate();
    // Initialize the Prefs class
    SharedPrefs.init(this);
}

Use it

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)

Use it with encryption

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 😎

Snapping the fingers 🔥 ( Clearing all data )

  • SharedPrefs.clear(context)