Image for post
Image for post

Kotpref: Easy SharedPreferences library for Kotlin android

Apr 20, 2018 · 1 min read

Using SharedPreferences needs some little boilerplate code. And if we store much more data or include/exclude specific data from auto backup, we should consider to split XML file.
Kotpref is the library to make you realizing it simply and ease.

To install, just add app dependency in build.gradle.

And call Kotpref.init(context) function in onCreate at Application class.

Kotpref requires defining data model to save into SharedPreferences. Data model can be created by extending `KotprefModel` like below.

You can now write and read by same way with normal property access!!

Saved SharedPreferences XML through Kotpref is separated by Class name. At the above example, file name is Profile.xml and content is below.

So, you can include/exclude each XML file (KotprefModel object) as auto backup target.

Kotpref core module only support basic SharedPreferences value type (String, Int, Long, Float, Boolean, String set). Although there are sub modules to support kotlin enum and gson serialized object.

Let’s try if you develop Android application with kotlin!

Kotpref and I welcome to your contiribute! Please feel free to give your feedbacks!

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade