Making Android offline edits survive process recreation

← Back to Blog & Articles

The unit of work is a change that must not be lost.

The durable artifacts are the store file, the outbox, and the tests that simulate a crash. The main hazard is a design that works only while the app stays alive.

Trace an edit. The user toggles a job. The model calls the repository, which updates the store and queues the operation in one write. The screen reads the new state. Later, the worker drains the outbox, and each delivered entry is removed. A failure at any arrow leaves a valid state.

Capture the baseline with ./gradlew :data:test. Add a failing test for a new operation type, then the operation, then its serialization, then the repository method. Bump the schema only if the stored shape changed, and write the migration test first.

For every write, ask what happens if the process dies before it, during it, and after it. For every retry, ask what makes it safe to repeat. For every merge, ask which side wins and what the user sees.

When data is missing or duplicated, check the outbox first. An entry that is still there was never delivered. An entry that was delivered but is still sent again has a key problem. Compare the store file before and after a sync.

Check that the base URL is HTTPS, that tokens are never logged or stored in the store file, that file names from users are sanitized, and that the store file lives in private storage excluded from backup. Check that error messages shown to a user do not include server text verbatim.

Test the failure modes, not the happy path. Test a crash between the two parts of a write, a repeated delivery, a lost response, a slow old refresh, and a newer schema. Fakes make each of those a few lines.

Treat the stored schema as a public contract. Never change a stored field without a migration and a test. Review the merge rule whenever the server API changes.

  • A change and its queued operation are written together.
  • Every operation carries an idempotency key.
  • The merge never discards unsent work.
  • The stored schema is versioned and migrated under test.
  • Cancellation is never swallowed.
  • Why do jobs and the outbox share one file?
  • What does the idempotency key protect against?
  • Why does a temporary failure stop the drain?
  • When would Room be a better choice than this file?

Continue with the book

Explore the full treatment, worked examples, and exercises in Agentic Android App Development.


Companion article for Agentic Android App Development, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.

Scroll to Top