This walks you through setting up an offline-first data layer with the Repository pattern as your single source of truth, Room for local persistence, and Retrofit for network calls. It covers the stale-while-revalidate pattern for reads (show cached data immediately, refresh in background) and touches on the outbox pattern for syncing writes. You'll use this when building any Android app that needs to work offline or reduce loading states by caching aggressively. The code examples are straightforward, showing a repository that exposes Room's Flow for reactive updates and a separate sync method for fetching fresh data. It assumes you're already using Hilt for dependency injection and doesn't dive deep into conflict resolution or advanced sync scenarios.

skills.sh installs
531
GitHub stars
1K
last updated
Aug 21, 2026

Install

$ npx -y skills add new-silvermoon/awesome-android-agent-skills --skill android-data-layer --agent claude-code

Installs into .claude/skills of the current project.

Files

Android Data Layer & Offline-First

Instructions

The Data Layer coordinates data from multiple sources.

1. Repository Pattern

  • Role: Single Source of Truth (SSOT).
  • Logic: The repository decides whether to return cached data or fetch fresh data.
  • Implementation:
    class NewsRepository @Inject constructor(
        private val newsDao: NewsDao,
        private val newsApi: NewsApi
    ) {
        // Expose data from Local DB as the source of truth
        val newsStream: Flow<List<News>> = newsDao.getAllNews()
    
        // Sync operation
        suspend fun refreshNews() {
            val remoteNews = newsApi.fetchLatest()
            newsDao.insertAll(remoteNews)
        }
    }
    

2. Local Persistence (Room)

  • Usage: Primary cache and offline storage.
  • Entities: Define @Entity data classes.
  • DAOs: Return Flow<T> for observable data.

Sponsors

Details

Repository
github.com/new-silvermoon/awesome-android-agent-skills
Categories
AI & Agent Building, Mobile Development
First seen
Jun 3, 2026

More from new-silvermoon/awesome-android-agent-skills

All 17
1plugin87 avatarmigrate-design-systemplugin87/ux-ui-agent-skillsMap this token system to or from any external design system (Material Design 3, Apple HIG, Fluent, Carbon, Ant, shadcn/ui, Radix, Chakra, Mantine, Bootstrap…) —531skills.sh installs
2aj-geddes avatarpayment-gateway-integrationaj-geddes/useful-ai-promptsIntegrate payment gateways like Stripe, PayPal, and Square with backends for payment processing, subscription management, and webhook handling. Use when buildin529skills.sh installs
3aj-geddes avatarprogressive-web-appaj-geddes/useful-ai-promptsBuild progressive web apps using service workers, web manifest, offline support, and installability. Use when creating app-like web experiences.529skills.sh installs
4automattic avatarwp-plugin-developmentautomattic/agent-skillswp plugin development529skills.sh installs
5rainlib avatarscriptwriter-skillrainlib/ai-storyboardUse when creating episodic scripts, ensuring series continuity, adapting story concepts into visual narratives, or preparing scripts with sufficient beats for s529skills.sh installs
6aj-geddes avatarkpi-dashboard-designaj-geddes/useful-ai-promptsDesign and build dashboards that track key performance indicators. Select relevant metrics, visualize data effectively, and communicate insights to stakeholders528skills.sh installs