android-offline-first
Skill11 starsChanged 8 months agoMITView on GitHub
Use when implementing local data persistence, offline synchronization, or background data fetching for Android.
In this repository40 other files it gives its agents.
- .github/copilot-instructions.mdCopilot instructions
- android-accessibilitySkill
- android-adaptive-layoutsSkill
- android-adb-terminalSkill
- android-background-executionSkill
- android-bluetooth-bleSkill
- android-build-verificationSkill
- android-camerax-mlkitSkill
- android-ci-cd-expertSkill
- android-clean-architectureSkill
- android-code-review-expertSkill
- android-coroutines-expertSkill
- android-custom-drawing-canvasSkill
- android-design-system-m3Skill
- android-design-to-codeSkill
- android-detekt-expertSkill
- android-enterprise-securitySkill
- android-gemini-nanoSkill
- android-google-workspace-expertSkill
- android-gradle-expertSkill
- android-hardware-testingSkill
- android-jetpack-composeSkill
- android-kmp-compose-uiSkill
- android-kmp-platform-channelsSkill
- android-kmp-sharedSkill
- android-ktlint-formattingSkill
- android-lint-and-qualitySkill
- android-local-stt-ttsSkill
- android-location-mapsSkill
- android-macrobenchmarkSkill
- android-media3-exoplayerSkill
- android-media-and-image-expertSkill
- android-motion-animationsSkill
- android-navigation-expertSkill
- android-performance-auditSkill
- android-rag-localSkill
- android-screenshot-testingSkill
- android-security-hardenedSkill
- android-unit-testingSkill
- android-wear-os-composeSkill
The file
We split this skill into the rules it gives an agent
8 rules. About 0 are common, 6 are distinctive, and 2 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈6
Distinctive · estimate
This author's own choices. Worth a look.
2
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 51
Use Kotlin Flows for observing database changes.
- Distinctive: line 52
Use Transactions for atomic operations.
- Distinctive: line 53
Always implement Migrations for schema changes.
- Distinctive: line 56
Use for tasks that MUST complete even if the app closes (e.g., uploading a post).
- Distinctive: line 60
Use for user preferences, simple settings, or session tokens.
- Distinctive: line 66
Periodic Sync: Use WorkManager to sync data every few hours.
- Very specific: line 78
Room Tests: Test migrations and DAO queries in a separate androidTest.
- Very specific: line 79
WorkManager Tests: Use WorkManagerTestInitHelper for unit testing workers.
≈ “Common” is an estimate: at least 1 in 5 of the 213,897 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Android Offline-First Excellence 📶🛡️
Standard patterns for architecting professional-grade Android applications that are resilient to poor network conditions and function seamlessly offline.
⚡ When to Use
- Local Persistence: Caching API responses in Room.
- Sync Logic: Synchronizing local changes with remote APIs.
- Background Work: Using WorkManager for data-heavy tasks.
- Reliable Data Fetching: Building "SSOT" (Single Source of Truth) repositories.
- Conflict Resolution: Managing data versioning between local and remote.
🏗️ The Single Source of Truth (SSOT)
- Rule: The UI ALWAYS reads from the Local Database (Room).
- Rule: The Network Layer ALWAYS writes to the Local Database (Room).
- Architecture:
class MyRepository( private val localSource: RoomDao, private val remoteSource: APIInterface ) { fun getItems(): Flow<List<Item>> = localSource.observeAll() suspend fun refreshItems() { val items = remoteSource.fetchItems() localSource.insertAll(items) // UI updates automatically via Flow } } - Advanced (Paging 3): For large lists, you MUST use
RemoteMediator. The RemoteMediator intercepts the pagination request, fetches the remote page, dumps it into Room, and signals thePagingSourceto re-read from the DB.
🛠️ Essential Tools
1. Room (SQL Persistence)
- Use Kotlin Flows for observing database changes.
- Use Transactions for atomic operations.
- Always implement Migrations for schema changes.
2. WorkManager (Guaranteed Execution)
- Use for tasks that MUST complete even if the app closes (e.g., uploading a post).
- Set constraints:
NetworkType.CONNECTED,RequiresCharging(true).
3. DataStore (Key-Value)
- Use for user preferences, simple settings, or session tokens.
- Choose
Preferences DataStoreorProto DataStore(Type-safe).
🚀 Sync Strategies
- On Demand: Refresh data when the user opens the screen.
- Periodic Sync: Use WorkManager to sync data every few hours.
- Immediate Push: Sync with network changes via a BroadcastReceiver or callback.
📦 Data Resiliency Checklist
- Error Handling: Differentiate between network errors (Retry later) and server errors (Alert user).
- Optimistic UI: Update the local state immediately, then sync with the server in the background.
- Data Expiration: Add
timestampto local entries to decide when to refresh from the network. - Conflict Resolution: Use
onConflict = OnConflictStrategy.REPLACEor custom logic based on "last modified" fields.
🧪 Testing and Verification
- Room Tests: Test migrations and DAO queries in a separate
androidTest. - WorkManager Tests: Use
WorkManagerTestInitHelperfor unit testing workers. - Network Simulation: Manually test the app in "Airplane Mode".
🔗 Related Resources
- Android Offline-First Guide
- Clean Architecture Skill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

