SessionManager

Additional

Language
Kotlin
Version
1.2 (Jan 8, 2018)
Created
Jul 20, 2017
Updated
Oct 1, 2019 (Retired)
Owner
Chingiz Huseynzade (chingiz)
Contributors
MFlisar
Chingiz Huseynzade (chingiz)
Caro Hautamäki (carohauta)
Lauren Van Sloun (Ashera138)
4
Activity
Badge
Generate
Download
Source code
APK file

Promotion

SessionManager-Android

Small Shared Preference Library for Android

Download

You can download the source code for this project from Github's releases page.

You can also get the source code with Gradle:

Step 1. Add the JitPack repository to your build file. Add it in your root build.gradle at the end of repositories:

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

Step 2. Add the dependency

dependencies {
        compile 'com.github.Chingiz:SessionManager-Android:1.1'
}

How do I use SessionManager?

Before using SessionManager, initialize the SessionManager on your Application class.

public class SessionManagerApplication extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        new SessionManager.Builder()
                        .setContext(getApplicationContext())
                        .setPrefsName(SessionKeys.PREFS_NAME.getKey())
                        .build();
    }
}

Step 2 - Create an enum.

public enum SessionKeys {

    PREFS_NAME("test"),
    TEST("test");

    private String key;

    SessionKeys(String key) {
        this.key = key;
    }

    public String getKey() {
        return key;
    }
}

Step 3.

@Override
protected void onCreate(Bundle savedInstanceState) {
 ...
 SessionManager.putString(SessionKeys.TEST.getKey(), "I'm SessionManager");
 Log.d("Main ", "onCreate: "+SessionManager.getString(SessionKeys.TEST.getKey(), "1"));
}

License

MIT licensed, (c) @hchingiz