1 / 11
Build Android apps that keep working without a network: SQLite and Room from the ground up, entities, DAOs, relations, type converters, full-text search, reactive Flow queries, transactions, schema export and migrations with tests, Preferences and typed DataStore, files and MediaStore, Paging 3…
Local Databases, Migrations, Reactive Queries, Preferences, Sync, and Conflict Resolution
Read before you buy: the PDF here is a free sample — the first 20 pages of the 460-page book (payments, sales and reviews on this demo site are sample data). Get the full e-book at thenexbooks on Gumroad.
Make your Android app work on the trail, in the subway, and on a plane — and catch up safely when the network returns.
Mobile networks fail all the time, and users do not stop using your app when they do. Offline-first apps keep the truth on the device: the UI reads from a local database, every change is saved locally first, and synchronization happens in the background, with retries and clear rules for conflicts. Getting there takes more than a Room tutorial. You need migrations that never lose data, queries that keep screens up to date, settings and small state stored correctly, long lists that page smoothly, a reliable sync engine, and tests that prove it all works.
This book teaches those pieces together by building the data layer of one realistic app, step by step, explaining why each tool works the way it does before showing how to use it.
What's inside
- Offline-first thinking: what belongs in Room, DataStore, files, or memory, and why the local database is the single source of truth
- SQLite on Android from first principles, then Room: entities, DAOs, the database class, compile-time checked SQL, and KSP setup
- Queries in depth: projections, upserts, conflict strategies, indices, type converters for time and enums, and embedded values
- Relationships: one-to-many and many-to-many with foreign keys, cascades, junction tables, and @Relation result classes
- Reactive queries with Flow, Room's invalidation model, and transactions that keep multi-step writes atomic
- Fast trail search with FTS4: content tables, safe MATCH queries, prefixes, and the pitfalls nobody mentions
- Evolving a shipped schema: exported schemas, AutoMigrations with rename specs, manual migrations with data backfills, and MigrationTestHelper tests for every upgrade path
- Preferences DataStore for settings (including migrating from SharedPreferences) and a typed DataStore with kotlinx.serialization
- Journal photos: the photo picker, app-private files, MediaStore export, and keeping files consistent with database rows
- Paging 3 from Room and from the network with RemoteMediator, remote keys, and cache timeouts
- Offline-first sync: client-generated IDs, soft deletes, an outbox written in the same transaction, WorkManager with constraints and backoff, cursor-based pulls, and idempotent pushes
- Conflict resolution with versions: detecting conflicts, explicit merge rules, tombstones, and a fully worked example
- Honest sync status in the UI, connectivity handling, and stuck changes that need attention
- Testing the whole data layer on the JVM with Robolectric, Turbine, fakes, paging-testing, and work-testing
- Production readiness: query plans and indices, backup rules, encryption options, privacy, and deleting user data
One running example, start to finish. You build the data layer of Waypoint, a fictional hiking trip planner and tracker from the fictional studio Northbeam Labs: a cached trail catalog with search, trips with GPS track points, a private journal with photos, settings, paging, and background sync with a backend that sometimes disagrees. You start from a small, tested starter project and grow the database through six schema versions, all covered by migration tests.
Current and honest. At the time of writing the book uses Room 2.8, DataStore 1.2, Paging 3.5, WorkManager 2.12, and Kotlin 2.4 with KSP, and it says so whenever a detail may change. Every query result and test output printed in the book comes from running the code; device-only behavior is clearly labeled. No invented benchmarks or statistics. Every chapter includes complete Kotlin code, Tips, Notes, Warnings, Try It Yourself exercises, and Key Takeaways, and the appendices give you a cheat sheet, templates and reference tables, an offline-first production checklist, and a glossary.
Format: PDF, 460 pages (A4), linked table of contents and bookmarks. English. First Edition, 2026. Published by thenexbooks. Includes the Waypoint starter project (Gradle, Kotlin) used throughout the book. Requires JDK 21 and the Android SDK (Android Studio recommended) to build the code. This book is independent and is not affiliated with, sponsored by, or endorsed by Google or JetBrains. Android is a trademark of Google LLC.
Table of Contents
Part I — Local Data Foundations
- Ch 1 · Offline-First Android: Why Local Data Comes First
- Ch 2 · SQLite on Android: The Engine Under Room
- Ch 3 · Your First Room Database: Entities, DAOs, and the Database Class
- Ch 4 · DAO Queries in Depth: Parameters, Projections, Upserts, and Indices
Part II — Room in Depth
- Ch 5 · Type Converters, Enums, and Embedded Values
- Ch 6 · Relationships: One-to-Many, Many-to-Many, and Foreign Keys
- Ch 7 · Reactive Queries with Flow
- Ch 8 · Transactions and Concurrency
- Ch 9 · Full-Text Search for Trails with FTS4
Part III — Evolving the Schema
- Ch 10 · Schema Export and a Versioning Strategy
- Ch 11 · AutoMigrations: Added Columns, Renames, and Specs
- Ch 12 · Manual Migrations and Data Transformations
- Ch 13 · Testing Migrations with MigrationTestHelper
Part IV — Preferences, Files, and Paging
- Ch 14 · Preferences DataStore: Settings Done Right
- Ch 15 · Typed DataStore with kotlinx.serialization (and Proto)
- Ch 16 · Files, MediaStore, and Journal Photos
- Ch 17 · Paging 3 from Room
- Ch 18 · Paging from the Network with RemoteMediator
Part V — Offline-First Sync
- Ch 19 · The Offline-First Repository: Room as the Source of Truth
- Ch 20 · The Outbox Pattern: Recording Local Changes
- Ch 21 · Syncing with WorkManager
- Ch 22 · Conflict Resolution
- Ch 23 · Sync Status, Connectivity, and Errors in the UI
Part VI — Testing and Production
- Ch 24 · Testing the Data Layer on the JVM
- Ch 25 · Testing Sync End to End
- Ch 26 · Performance and Debugging: Query Plans, Indices, and Inspection
- Ch 27 · Data Safety: Backup, Encryption, Privacy, and Deleting User Data
- Ch 28 · Case Study: Waypoint's Offline-First Data Layer, End to End
Appendices
A · Room, DataStore, and Paging Cheat Sheet
B · Templates and Reference
C · Offline-First Production Checklist
D · Glossary
Book details
| Detail | |
|---|---|
| Pages | 460 |
| Format | PDF (A4) + Waypoint starter project (Gradle) |
| Language | English |
| Level | Intermediate |
| Edition | 1st Edition (2026) |
| Download on this site | Free sample, first 20 pages (PDF) |
| Publisher | thenexbooks |
Files you get
No reviews yet. Only buyers can review.
More from thenexbooks