Reputation: 16869
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?
Upvotes: 2
Views: 2362
Reputation: 16869
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.
Upvotes: 0
Reputation: 1621
Take a look at Jackson: http://wiki.fasterxml.com/JacksonDataBinding
If you have a standard Java model inside your app, Jackson will help you convert it to JSON, which you can send easily to a central server.
When you pull down new routes from your central server, you'll simply use Jackson to deserialize the JSON back into your Java model.
Upvotes: 0
Reputation: 2669
You should create a server application which will handle all your client's data exchanges. Your server application have to be linked to your database. Also your client application(ak: Users) will communicate only with the server application which will refresh your other clients applications. Take a look at Java socket and remember to put them in a AsyncTask class (similar to Thread, but used only for android).
Upvotes: 2