This technical guide is editorial content prepared for this website. It is not an article previously published by Nihat Akbuğa or a description of a specific project's internal architecture.
Local data first
In a field application, connectivity is a variable the user cannot control. Waiting for a network response every time a screen opens makes the working experience depend on that variable. Android's offline-first guidance treats the local data source as the primary source for reads.
The interface can observe server responses written to local storage. This separates data reads from network access. Users can see the last known data while an update continues in the background.
Make state visible
A local record does not necessarily mean the data is up to date. The interface should distinguish between an update in progress, the display of last known data, and an operation awaiting synchronization.
// Conceptual example: not production code.
interface FieldRepository {
fun observeTasks(): Flow<List<FieldTask>>
suspend fun refresh()
}
This boundary keeps the screen that reads data independent of a particular HTTP client or database. It does not, by itself, resolve conflicting writes.
Writes need a separate decision
When a user creates a record without a connection, the product's business rules come into play. The operation might be accepted locally, queued, or require connectivity if it is critical. Each option should be explained clearly to the user.
Retried requests should not create duplicate records. Server-side idempotency therefore needs to be designed together with the client's retry policy. Conflict resolution depends on the type of data; last-write-wins is not appropriate for every domain.
What should be tested?
Opening a screen in airplane mode is not enough. Tests should also cover losing connectivity during a request, restarting the application, editing the same record on different devices, and attempting synchronization with an expired session.
The purpose of these tests is to verify that the user's work is preserved and its state is communicated accurately, rather than merely confirming that an abstraction exists.
Source
Android Developers — Build an offline-first app. This article explains general engineering principles and contains no details of a real client system.