Skip to content

chingiz/SessionManager-Android

Repository files navigation

SessionManager-Android ko-fi

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