datastore

Store user preferences with Android DataStore using Preferences or Proto.

14|Updated Mar 14, 2026
One-click install
npx skills add https://github.com/piyushverma0/android-agent-skills --skill datastore-piyushverma0
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: datastore
Source: https://github.com/piyushverma0/android-agent-skills/tree/main/skills/datastore
Command: npx skills add https://github.com/piyushverma0/android-agent-skills --skill datastore-piyushverma0

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

DataStore is the modern replacement for SharedPreferences, enabling coroutine-based, type-safe storage for lightweight user data such as preferences, theme settings, onboarding state, and non-secure tokens. It also provides a straightforward migration path from SharedPreferences and integrates smoothly with DI and repository patterns.

Core Features & Use Cases

  • Preferences DataStore for simple key-value storage with type-safe keys and Flow-based observation.
  • Proto DataStore for complex structured data with generated serializers.
  • Automatic migration from SharedPreferences to preserve existing user data and ease app upgrades.
  • DI-ready modules and repository patterns for clean, testable data access.
  • Use Case: Persist user theme, language, and onboarding state across app restarts and configuration changes.

Quick Start

Create a DataStore instance and read or write a sample preference using a coroutine-based repository.

Frequently Asked Questions about datastore

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I migrate from SharedPreferences to DataStore in Android Kotlin?

You can migrate from SharedPreferences to DataStore automatically to preserve existing user data. The DataStore migration process maps your old preference keys to the new type-safe DataStore keys during initialization, easing app upgrades without data loss.

What is the best way to store user preferences in Android Kotlin coroutines?

The best way to store user preferences in Kotlin coroutines is using DataStore. It provides type-safe access and Flow-based observation, replacing SharedPreferences for reliable asynchronous reads and writes of lightweight settings like themes and onboarding flags.

When should I use Proto DataStore instead of Preferences DataStore?

Use Proto DataStore when you need to persist complex structured data with generated serializers. Preferences DataStore is better suited for simple key-value storage with type-safe keys, while Proto handles intricate data models efficiently.

Does DataStore work with Dependency Injection and repository patterns?

Yes, DataStore integrates smoothly with Dependency Injection and repository patterns. It provides DI-ready modules that ensure clean, testable data access for your Android app's preference storage layer.

How do I observe DataStore preference changes in Android?

You observe DataStore preference changes by collecting the Flow emitted by the DataStore instance. This coroutine-based Flow mechanism allows asynchronous, type-safe observation of user preferences like theme settings across configuration changes.

Can DataStore handle onboarding state and language preferences across app restarts?

Yes, DataStore can handle onboarding state and language preferences across app restarts. It persists lightweight user data reliably using Preferences or Proto DataStore, ensuring settings remain intact during configuration changes.