android-data-layer

Android Data Layer & Offline-First

Safety Notice

This listing is imported from skills.sh public index metadata. Review upstream SKILL.md and repository scripts before running.

Copy this and send it to your AI assistant to learn

Install skill "android-data-layer" with this command: npx skills add new-silvermoon/awesome-android-agent-skills/new-silvermoon-awesome-android-agent-skills-android-data-layer

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) } }

  1. Local Persistence (Room)
  • Usage: Primary cache and offline storage.

  • Entities: Define @Entity data classes.

  • DAOs: Return Flow<T> for observable data.

  1. Remote Data (Retrofit)
  • Usage: Fetching data from backend.

  • Response: Use suspend functions in interfaces.

  • Error Handling: Wrap network calls in try-catch blocks or a Result wrapper to handle exceptions (NoInternet, 404, etc.) gracefully.

  1. Synchronization
  • Read: "Stale-While-Revalidate". Show local data immediately, trigger a background refresh.

  • Write: "Outbox Pattern" (Advanced). Save local change immediately, mark as "unsynced", use WorkManager to push changes to server.

  1. Dependency Injection
  • Bind Repository interfaces to implementations in a Hilt Module. @Binds abstract fun bindNewsRepository(impl: OfflineFirstNewsRepository): NewsRepository

Source Transparency

This detail page is rendered from real SKILL.md content. Trust labels are metadata-based hints, not a safety guarantee.

Related Skills

Related by shared tags or category signals.

Automation

gradle-build-performance

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

compose-ui

No summary provided by upstream source.

Repository SourceNeeds Review
Automation

android-testing

No summary provided by upstream source.

Repository SourceNeeds Review