سؤال

Im am developing a webservice for an App that I am writing. I want to make the App offline accessible.

I made that webservice so that if you request JSON from the webservice you can give a date: /color/colors/date/2014-03-01T12:00/

If you don't give the date you will get everything that is inside the database and that is active. If you give the date you will only get everything that is updated after that date.

Now my problem is that if I remove something from the webservice of from the App then it will not be synced and the other devices will never know that it is removed.

I could work with a field where I say that a record is removed but then I need to keep every record and I can't delete any record.

Is there a better way to do the syncing? Or what is the best way?

هل كانت مفيدة؟

المحلول

I think there is no possible way to detect the deleted entry's change, unless you send the information that the entry is deleted. The best practise you set a field in the table with integer type, then you can set this value on updates. You don't have to set it only 1 or 0, you can use bigger numbers (for example I used 30 on that entries, that I deleted on 20th march , on this day was a big code logic change. after that i knew when the status integer is 30, then i deleted this row after that date.) It may be a silly example, but you can implement your own logic.

نصائح أخرى

It depends on how important it is to update the rest of the devices when a change is made.

If it is critical, then it would be worth implementing push notifications or something similar to each device to let them know about the updated situation. Otherwise, you would simply have the other devices poll the server to check for changes on their own accord, and the frequency or the trigger of this poll would depend again on how critical it was that they get an update. Maybes they only need updating when they visit a certain activity, so in that case you would only poll when you reach the onResume() event of that activity

Update

If you don't need to keep a history of the deleted record, then why can't you just delete it, and then when the rest of the devices update, you clear all and download a fresh set? If that is too intensive, you would NEED to have a reference to the id, which you could do in a table or use a special value in the field (like null, 0 or -1) to mark it. Otherwise there would be no way to reference it

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top