android-data-layer

Implements offline-first Android data layer with Room, Retrofit, WorkManager, and Hilt.

915|88|Updated Feb 6, 2024
One-click install
npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill android-data-layer-new-silvermoon
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: android-data-layer
Source: https://github.com/new-silvermoon/awesome-android-agent-skills/tree/main/.github/skills/android-data-layer
Command: npx skills add https://github.com/new-silvermoon/awesome-android-agent-skills --skill android-data-layer-new-silvermoon

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

This Skill helps Android teams implement a robust data layer by coordinating a Repository pattern with a local Room cache and a Retrofit-based remote source, enabling offline-first synchronization and a single source of truth.

Core Features & Use Cases

  • Single source of truth: Centralizes data access through a Repository that decides when to serve cached data or fetch fresh data.
  • Local persistence (Room): Stores entities locally and exposes observable data via Flow.
  • Remote data (Retrofit): Fetches data from backend with suspend functions and handles errors gracefully.
  • Synchronization strategies: Implements "Stale-While-Revalidate" and the "Outbox Pattern" using WorkManager for background sync.
  • DI integration: Binds repository interfaces to implementations via Hilt.

Quick Start

Create a NewsRepository wired to NewsDao and NewsApi; implement refreshNews() to synchronize remote updates into local storage.

Frequently Asked Questions about android-data-layer

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

FAQPage Schema
How do I implement an offline-first data layer in Android with Room and Retrofit?

An offline-first data layer coordinates a Room local cache with a Retrofit remote source via the repository pattern. It serves observable data from the local database using Flow while synchronizing remote updates through suspendable network calls.

How does the single source of truth pattern work with Android Room and Flow?

The single source of truth pattern centralizes data access in a Repository that always serves local Room entities via Flow. The Repository fetches fresh data from the remote source and updates the local database, ensuring the UI observes a single, consistent local cache.

How do I synchronize remote data in the background using WorkManager for an Android app?

Background synchronization uses WorkManager to implement strategies like Stale-While-Revalidate and the Outbox Pattern. WorkManager orchestrates fetching remote data via Retrofit and persisting updates into the local Room database when the app is backgrounded.

Does this offline-first repository pattern require dependency injection with Hilt?

Yes, this approach is designed for architectures using Clean Architecture with Hilt. Hilt binds the repository interfaces to their concrete implementations, managing the dependencies for Room, Retrofit, and WorkManager synchronization components.

How do I handle Retrofit network errors in an Android repository?

Network errors are handled gracefully using error handling wrappers around suspendable Retrofit calls. The repository catches remote fetch exceptions and relies on the local Room cache to continue serving data, maintaining an offline-first experience.

What is the best way to observe local database changes in Android using Kotlin Flow?

The best way is exposing Room queries as Flow<List<Entities>> through a Repository. This allows the UI to reactively observe local database changes, automatically updating whenever the remote synchronization process writes fresh data into the local cache.