Search code examples
androiddatabasesynchronizationdata-sharing

Android App: Sharing data between users


I am developing an android app for building and sharing a database of bike trails.

Users will be able to add their own locations and trails to their local copy of the database, or edit existing descriptions, details, etc.
I would like some mechanism where all users of the app could share their data with one another. For instance, through a central web-based database or something. It doesn't really work to just upload the entire database, because I am anticipating there will be times when several users will want to make edits at the same time, possibly to the same object.

Is there a defined "best practice" for accomplishing this kind of data-sharing?


Solution

  • I think the algorithm should be something like this:

    Note: you need a good way of determining whether 2 locations are the same or not. Presumably a single location could have different names or spellings, and slightly different GPS coordinates. Also, multiple trails might start at the same GPS coordinates.

        Iterate through the remote records, one by one
          If the location doesn't exist locally
            create it.
          else if the record is identical
                 ignore it
               else 
                 if only one record changed
                   copy it to the opposite database
                 else
                   merge the data from the 2 records together somehow
    

    Finally, you would need to upload any locally created records to the remote database.