Why implement android SyncAdapter?
As an android developer you could be asking your self a question: Why implement android SyncAdapter?
It really depends on your android App.
When should you need to consider implementing SyncAdapter?
If you have not all ready watch Google I/O 2010 – Android REST client applications
If your app needs to sync local data (new/changed) to your server.
A great example would be a note app. You want your user to have the ability to create notes without internet connection and on connectivity to the internet sync new/change notes.
SyncAdapter sync could be trigger by the user or by the system.
1. Authentication -> to validate user and get token.
2. ContentProvider -> Local storage access (sqlite etc)
3. Your Custom methods for syncing (SyncHelper).
Here is a quick flow chart that should help you to get a better understanding of SyncAdapter.
- SyncAdapter is trigger, getAuthToken() from Authenticator
- If token Authenticator will return token else get token from system (if username and password stored in AccountManger) else show Login Activty/Fragment
- Validate user return token and add user to AccountManager
- SyncAdapter will pass token to processor (SyncHelper in my case)
- SyncHelper custom class has methods of checking your db if there is anything to sync.
- Content Provider will be used to get data from db and notify Fragments/Activities for changes (not in the diagram)
- Return data that needs to be synced.
- SyncHelper will get the data ready and pass it to HTTP Client
- HTTP Client will process the request and send it to server
- HTTP Client will check if request data was OK if not send invalid Token Authenticator
- Return good data to SyncHelper, SyncHelper will send insert/update/delete as needed to Content Provider.