DEV Community

Alex Devson
Alex Devson

Posted on

Stop Writing SharedPreferences Boilerplate — Use EasyPeasy Insteadandroid

Every Android developer has written this code a hundred times:

SharedPreferences prefs = getSharedPreferences("myPrefs", MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("username", "John");
editor.apply();
// And then to read...
String username = prefs.getString("username", "");
Enter fullscreen mode Exit fullscreen mode

4 lines just to save a string. Multiply that across your entire app and you've got a maintenance nightmare.

Enter EasyPeasy 🍕

// Save anything
EasyPeasy.putData("username", "John");

// Read it back
String username = EasyPeasy.getData("username");
Enter fullscreen mode Exit fullscreen mode

That's it. One line to save, one line to read. Works with any serializable object — strings, integers, lists, custom objects, you name it.

What Makes It Special

  • 🔥 2 lines replace 10+ — no more Editor, apply(), commit() boilerplate
  • 📦 Stores any object — uses Gson serialization under the hood
  • 🪶 Tiny footprint — adds virtually nothing to your APK size
  • 🛡️ Type-safe — generic methods with proper type inference
  • Zero configuration — just initialize once in your Application class

Quick Setup

implementation 'com.github.p32929:EasyPeasy:1.0.2'
Enter fullscreen mode Exit fullscreen mode

Initialize once:

EasyPeasy.init(this); // In your Application class
Enter fullscreen mode Exit fullscreen mode

Then use everywhere — Activities, Fragments, Services, anywhere.

Real-World Use Cases

  • Save user preferences without a database
  • Cache API responses locally
  • Store onboarding state
  • Remember user's last selection

If you're still writing SharedPreferences.Editor by hand in 2026, give this a try.

GitHub: github.com/p32929/EasyPeasy-Android

Star it if you find it useful! 🌟

Top comments (0)