Search code examples
androidandroid-sqliteandroid-contentproviderandroid-syncadapter

SyncAdapter - detect when to synchronize server with the client (mobile)


I have a form inside my mobileApp to add a new item.
When there are no internet connection, and that an item is added to sqlite localdb, I want this data to be uploaded to the server (synced), once device is connected to the internet.

I have implemented a SyncAdapter, coupled with a simple ContentProvider, but I dont know how to detect that a row need to be created/updated/deleted on the server.

Do I need to add a flag column to the table (having values created/updated/deleted/none) and if that's the case, is the uploading to the server done with just a call to server api methods or with ContentResolver.

My last question is where do I place this code? inside performSync() method? or I have to add a receiver which react when mobileapp is connected to internet.


Solution

  • The content provider does notify sync adapter when a modification occured on local db.