Android vs. Web Sync

5

I'm developing an application that will work offline on android and synchronize with a web version. I have API that will intermediate this synchronization.

Currently the android version has a timestamp to control the changes in the registry, and the idea was to synchronize with API to check the records with update date greater than the date of the last synchronization

But the question is how to control changes in the android clock because the user may have the correct time or date. This could happen if the device's time is shorter than the last synchronization so that it does not send the changed data.

    
asked by anonymous 29.01.2016 / 00:34

1 answer

4

The method System.currentTimeMillis () returns how many milliseconds have passed since at midnight on 01/01/1970. The problem is that it can be changed by the user or the cellular network itself.

Your application can detect when this clock changes by listening to the following broadcasts:

The biggest problem is that you do not have any control over the clock of the device, knowing that you can think of a logic that meets your need, it can be simple or complex.

An alternative

In case the time is not important, instead of using timestamp, why not use a version number? This eliminates all the problems that a timestamp has.

Incremental

It can be incremental , your server sends a version number, eg 1 , next update 2 and so on. The App compares the version at the time of syncing, updates if it is smaller than the server.

Unique identifier

Or it can be a unique identifier , as a GUID java.util.UUID.randomUUID(); . Your server sends this guid. The app compares if the guid it has is different from the server, it updates if it is different.

    
10.08.2016 / 22:23