java - Prevent network sync loop when syncing from network in Android ContentProvider -


i'm writing own contentprovider synced web service using syncadapter.

problem happens when sync adapter modifying content provider's data provider triggers network sync when internally calling getcontentresolver().notifychange causing sync loop.

the notifychange network sync flag required when client application modification should avoided when sync adapter modifying.

how can one, inside contentprovider, easly tell if it's being used client application (which should trigger network sync upon modification) or sync adapter (which should not trigger network sync).

currently i'm using different content_uri's (sync adapter accesses data using content_uri_no_sync , client apps using content_uri) able distinguish between 2 types of access , set network sync flag accordingly.

watch this video rest api usage in syncadapters.

the method discuss add set of metadata flags columns database. allows 3 things.

  1. the flags allow syncadapter determine rows need changes , changes are. how tell difference between locally created row , locally modified row? furthermore how know rest api call make? if delete row, how syncadapter know row deleted if data gone? instead, set "should deleted" flag, , then, when syncadapter runs, knows push delete server.

  2. the flags allow cursoradapter modify view created (like adding spinner show "this row being synced")

  3. finally, , don't point out, flags allow tell why row being modified. if none of flags set , row changes, must have been because of update server. therefore, no need sync network.

so, 2 workflows follows:

local change

  1. app creates new row. row "create" flag true.
  2. contentprovider stores row, sees create flag , calls notifychange(...,true);
  3. sync network = true (the final parameter) causes syncadapter fire.
  4. syncadapter scans database, finds row create flag set , performs appropriate server action. after success, syncadapter clears flag.(row update on contentprovivder)
  5. contentprovider sees flag clear, no flags left set, calls notifychange(...,false);
  6. contentobservers see flag change, update "sync finished"

all these steps equivalent update / delete -- 1 flag per syncable row each of create/update/delete. notice other win -- if "create" fails temporarily? server down... how know retry? -- simple, don't clear "create" flag , see 15 minutes later.

remote change

  1. syncadapter fires due periodic sync.
  2. syncadapter fetches update server. pushes changes database. doesn't set flags. contentprovider sees lack of flags, knows change must have come server (or isn't database change needs pushed server), calls notifychange(...,false);
  3. contentobservers see content change , update new row data

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -