
Android Data Layer
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-codeInstalls 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
@Entitydata 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- Android Retrofit495
- Coil Compose464
- Xml To Compose Migration451
- Compose Navigation438
- Rxjava To Coroutines Migration347
- Android Testing869
- Gradle Build Performance809
- Compose Ui760
- Android Gradle Logic738
- Android Architecture701
- Kotlin Concurrency Expert684
- Compose Performance Audit596
- Android Emulator Skill578
- Android Viewmodel576
- Android Coroutines569
- Android Accessibility560