StoreBox by

Android library for streamlining SharedPreferences.

When getting a value from any preferences, whether private Activity or default shared preferences, you would normally have to get a reference to a SharedPreferences instance, for example using

SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(context);

And after that the values can be retrieved/saved.

String username = preferences.getString("username", "");
preferences.edit().putString("username", "androiduser").apply();

This can get tedious if the values need to be saved and retrieved from multiple places as the caller is always required to supply the key of the preference, know under what type it is saved, and know the appropriate default to be used for the invocation. With a bigger set of keys used throughout an application this approach can become increasingly error-prone. Putting commonly accessed preferences behind a wrapper is a solution which is commonly used, however there is an alternative.