Easy Android Preferences with Bulldog. No more boilerplate code !

Sérgio Serra
1 min readOct 22, 2018

--

Never write code like this anymore

prefs.edit().remove("id").apply()

or this

PreferenceManager.getDefaultSharedPreferences(this)
.edit()
.putBoolean("aBool",true)
.apply()

all over you code base.

Bulldog uses annotation processing and Kotlin delegated properties to simplify reading and storing values in Android preferences.

With Bulldog we can read and write values just like a normal object

UserSettings().id = 4
Log.d("UserId", UserSettings().id)
// Output 4

But how does it works ?

1- First import dependencies in build.gradle

2- Init BulldogContext in App class.

3- Define your model using an object annotated with @Bulldog, here you can also set default values for each property.

4- Bulldog will generate a classe at compile time with the name UserSettings. Use this class to read and store values, under the hood is uses Android preferences to store and retrieve values.

Generated class contains a clearXXX() method for each property and a human readable toString() implementation.

Read values

Just access object property like a normal object.

Write values

Clear values

Bulldog generates a clear method for each entry.

Print information

Bulldog also generates a toString() human readable implementation.

Enum support

Bulldog supports Enum type using the @Enum annotation.

For more info take a look at:

Thanks that’s all !!!

Sérgio Serra @Android Developer

sergioserra99@gmail.com

--

--

Sérgio Serra

Android Enthusiast, Mobile developer, UI/UX fan, like to great user experiences.