Over a million developers have joined DZone.
{{announcement.body}}
{{announcement.title}}

Handling Write Conflicts Server-Side in Offline-Enabled Mobile Apps

DZone's Guide to

Handling Write Conflicts Server-Side in Offline-Enabled Mobile Apps

Introducing an 'offline first' mentality to your app development has become a lot easier.

· Mobile Zone
Free Resource

Download this comprehensive Mobile Testing Reference Guide to help prioritize which mobile devices and OSs to test against, brought to you in partnership with Sauce Labs.

Alpha Anywhere’s built-in support for offline access makes it easy to build mobile applications that work anywhere – with or without a network connection. Users can continue to work without fear of losing data when their network connection is lost. Work can be saved back to the system of record when a device acquires a network connection through a process called “synchronization”.

Offline Synchronization

Synchronization is a two-fold process. While the user was working offline, changes may have been made by other users to the records of interest. New information is downloaded from the server while local changes made on the device are uploaded and saved. It is possible that the same record has been modified in both locations – on the device and in the database. This can create “write conflicts”. When a write conflict occurs, the conflicting changes need to be resolved before the synchronization process can be completed.

The out-of-the-box behavior in offline-enabled apps prompts the user to decide what should happen when write conflicts occur. The user is prompted to tap on fields with write conflicts and choose a conflict resolution action. Users can choose one of two options when resolving a write conflict: “Use mine” or “Use theirs”. Choosing “Use mine” will save the changes from the mobile device to the database, overwriting the value in the system of record. “Use theirs” discards the change in the mobile app, leaving the data in the database unchanged. When all write conflicts are resolved, synchronization can be completed.

Handling Write Conflicts in Offline Mobile Apps for Users

In some situations, it may be desirable to handle write conflicts programmatically instead of allowing users to decide what should happen. Alpha Anywhere provides server-side events that you can utilize to add your own custom write conflict handling, allowing you to decide which value to keep. You could also choose to use neither value, entering your own custom values to be saved.

Handling write conflicts programmatically is done server-side via xbasic. An xbasic function can be called when the server-side “On write conflict” is triggered for the List control. The xbasic function can specify how write conflicts should be handled for all records or on a case-by-case basis.

To learn more, watch the videos below:

Options for Handling Write Conflicts when Syncing Data Part 1
Options for Handling Write Conflicts when Syncing Data Part 2

Analysts agree that a mix of emulators/simulators and real devices are necessary to optimize your mobile app testing - learn more in this white paper, brought to you in partnership with Sauce Labs.

Topics:
mobile ,network ,data

Published at DZone with permission of Amy Groden-Morrison, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

{{ parent.title || parent.header.title}}

{{ parent.tldr }}

{{ parent.urlSource.name }}