Sync Adapter Overview

Sync Adapter, as its name it is use to sync device data with server data.

This sync can be done on following conditions:-

  • When server data is changed.
  • When device data is changed.
  • At regular interval or specific time.
  • On demand, such as user action.


First lets understand SyncAapter Framework. Sync Adapter framework has 4 basic components :-

  • Stub Authenticator. (For accessing account information.)
  • Stub Content Provider (Used when your data is other than SQL)
  • Syn Adapter (Entire Class runs in background thread. You on't need to create your own.)
  • Binder Service (This allow sync adapter framework to call authenticator method.)
Note:- Sync Adapter is not only used to sync SQL data, you can sync files, text, and other kind of data with sync adapter but for that need to use Stub Content Provider.

Stub Authenticator 


Now segregate all the information and come to the flow.
So when request Sync. Binder service runs and called onPerformSync after authentication.
Then code written inside onPeformSync will be executed and fetch data, after that content provider is notified and data is updated.

requestSync( ) - This method is used invoke sync or SynAdapter
addPeriodicSyn( ) - This method is to invoke periodic sync or sync at particular interval.

Reference:- 
Good for creating account authenticaor
https://www.pilanites.com/android-account-manager/
http://blog.udinic.com/2013/07/24/write-your-own-android-sync-adapter


Comments

Popular posts from this blog

Software Design Principles (SOLID)

Draw Over Screen App Example Android