What better way to work offline and synchronize data with server?


I'm working on a project where users will need to register offline and then submit their entries to the server as soon as the internet connection is available.

My problem is to know:

  • What is the best way to work offline? Preferably native Android.
  • When 2 users on different devices make a change in a person's information, how will I update them on the server?
asked by anonymous 16.02.2014 / 19:20

8 answers


The best way to keep information offline, on Android, is actually SQLite .

But for the update on the server, I believe the best procedure is to mark the update with a version code and a timestamp.

So, before sending the information to the server, you can check the configuration version and which of the competing versions is the most current one.

You can also create a "merge " rule on the server. Giving overlay preference to the latest data.

Another practice that can be very good is to show the user that there is a data conflict and ask him which version should be kept. An application that uses this method is Gameloft's "My Favorite Evil" (or "Minion Rush").

17.02.2014 / 15:20

To work offline with Android, you must use SQLite , a good tutorial can be found here .

In cases of changing the same record, the ideal is that every time a change is detected in an outdated record, block the change, update the record on the device with the new data and notify the user that it must redo the change in that registry.

I'm assuming you already have an API responsible for managing the data sent by the devices.

17.02.2014 / 02:31

A SIMPLE and EFFICIENT way to work with offline data and synchronization is to use a realtime database API . Because the API itself will keep your data synchronized, even offline, leaving you free of all the complexity of managing that data in two different banks.

I suggest using Firebase , which works with major platforms such as Android, iOS and Web, and has a free plan (maximum of connections of 50, 5 GB transfer of data, 100 MB of records in the bank).

26.05.2015 / 14:58

For the first problem use SQLite.

The second problem can be resolved with a Change Log on the server. When updating the information from the server to the device, you should get the id of the last log record along with the changeable information, and when synchronizing the changed information with the server, check if the log record you have is same as the last record of the server, if yes, changes and writes a new record in the log, if not, that means someone else has already made a change and added a new record, so that their last log record in the device is lower to the last log on the server.

17.02.2014 / 22:21

Like the previous answers, use SQLite to save to the device.

Services on Android (Documentation)

When the application opens, start a service that will synchronize with the server when it has internet connectivity, so it will synchronize automatically without the user having to interact to send / receive data.

17.02.2014 / 23:36

Regarding the first question, another database alternative is db4o .

It is object oriented, despite the rather weak documentation, it is much faster and more practical to use than relational database. Of course there are exceptions and limitations, but I think it's worth taking a look and testing.

The second question, can not escape much of what has been said previously. It is necessary to keep a record of the date of change. So when you have a connection, make a comparison of the change date to see which is the most current.

24.02.2014 / 20:06

Regarding the second question, you could have in the DB a field that, for example would start as 1.

And offline, they would make the changes, and then when they went online they would check which one would have the biggest field. If it were offline, then it would change the fields, if it were online nothing would happen.

See this as the version of a video game that uses a launcher. Each time it is started, it connects to BD to check if the version it has is the same as it is in the DB.

Of course, those who say with integers, also say with dates (it may even be easier to review the data change date later).

I hope I have helped x)

26.05.2015 / 15:43

If it is different data where only the id can generate conflict, the ideal solution for this is to use the id UUID template, which generates a code that will never be repeated and you do not have to worry if someone has already sent data with the same id as yours.

25.08.2015 / 13:56