0

I've been thinking about this scenario.

Let's say I have a SQLite database wrapped in a ContentProvider, The data in the database is sent to a webservice thorugh a SyncAdapter which runs every 10 minutes. To know which rows have been sent to the webservice, an state column is used (0 = not sent, 1 = sent).

The app UI is a list filled using a LoaderManager.LoaderCallbacks, and another view(a form) in which the user inputs the data.

The SyncAdapter uses the onPerformSync's ContentProviderClient parameter to query the data not sent (0) and to update the rows to a sent state(1)

The cause of my confusion is the scenario in which the already sent data can be re-sent several times. the user opens an already sent form and edits its data, which changes the state column to 0, so the syncadapter picks the edited row.

Now, Let's say the sync adapter picks a row and begins to send the data, meanwhile the user opens the same data row, edits some columns and updates. Then when the webservice finishes receiving the data, the sync adapter updates the state column to 1.

Now the row contains data that is not going to be sent. right?

should I just compare all the data I sent with the one in the database before updating from the sync adapter, is that the approach? Or could I use the framework to handle the situation in a more sophisticated manner?

Looking forward to hear what is you experience with that situation.

ILovemyPoncho
  • 2,762
  • 2
  • 24
  • 37

2 Answers2

2

You found that you have more than two states:

  • rows that have changed and must be sent (or re-sent);
  • rows that were sent, but not yet known to be accepted by the server; and
  • rows that are accepted by the server.
CL.
  • 173,858
  • 17
  • 217
  • 259
1

As @CL. correctly said you have more than 2 states.

a simple solution can be locking the rows from being edited while they are in transition.

Rahul Tiwari
  • 6,851
  • 3
  • 49
  • 78
  • good idea, but I don't think I would like to restric the user from editing. To make it transparent to the user, I would probably create a tmp table to store rows if the original row is in transition state, and once the sync adapter finishes, look for those tmp rows and update the original. I like that, definitely better than having only two states and comparing the data. thanks – ILovemyPoncho Oct 06 '15 at 15:27