Skip to content

An easy to use Shared Preference tools for android

License

Notifications You must be signed in to change notification settings

bytcore/prefs-droid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

prefs-droid

An easy to use wrapper tools for Shared Preference of android

Getting Started

Download from JCenter
or
Add dependency in your module build.gradle file

dependencies {
    compile 'com.binjar.prefsdroid:prefs-droid:1.1.0'
}

Initialize preference in the Application class

public class App extends Application {
    @Override
    public void onCreate() {
        super.onCreate();
        Preference.load().using(this).prepare();
    }
}

If you wish to add custom name of the shared preference use

Preference.load().using(this).with(PREFERENCE_NAME).prepare();

Usage

After initialization, you can save values to the shared preferences from anywhere in your app, such as:

Preference.putString(TEXT, textInput.getText().toString());

or save an object

User user = new User(name, age);
Preference.putObject(OBJECT, user);

You can get the object by passing the class of the User

User savedUser = Preference.getObject(OBJECT, User.class);

You can remove a single key

if (Preference.containsKey(KEY)) {
    Preference.remove(KEY);
}

or remove all keys by calling

Preference.clear();

Bonus

You can add @Type() source annotation to your preference keys which will help you to find easily what type of value is stored against that key. See smaple PrefsKey.java for usage.

License

This project is licensed under the MIT License - see the LICENSE.md file for details

Releases

No releases published

Packages

No packages published

Languages