• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Android sync adapter
 

Android sync adapter

on

  • 4,371 views

Android sync adapter by Anatoliy Kaverin

Android sync adapter by Anatoliy Kaverin

Statistics

Views

Total Views
4,371
Views on SlideShare
4,129
Embed Views
242

Actions

Likes
6
Downloads
79
Comments
2

5 Embeds 242

http://odmob.blogspot.com 129
http://www.odmob.blogspot.com 82
http://odmob.blogspot.ru 19
http://odmob.blogspot.ie 6
http://www.odmob.blogspot.ru 6

Accessibility

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel

12 of 2 previous next

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
  • Video recording in Russian:
    http://www.youtube.com/watch?v=26n-W344ArI&list=PLbNke4McFRtQ6nsiI5SbmlsZq0LfZeEAF
    Are you sure you want to
    Your message goes here
    Processing…
  • Amazing presentation, thx !
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

    Android sync adapter Android sync adapter Presentation Transcript

    • DEVELOPING ANDROID CLIENT APPS VIA SYNCADAPTER Anatoliy Kaverin Lohika @ 2013
    • SESSION AGENDA  Why?  SyncAdapter!? LOLWUT?  The big picture  Puzzles  Does anybody use it?  Code samples, documentation  Q&A 2
    • IMAGINE… SIMPLE CLIENT-SERVER APP 3
    • SYNC CACHE: ISSUES TO CONSIDER Are we done?  Global Sync setting  Bandwidth starvation  YES, queued  YES, even duplicates  YES, even if app is off  YES, built in support Hand-made  SyncAdapter framework  Network availability  Pending queue  Refresh on network  Periodic update  YES, manual override  YES! YES! YES! 4
    • SYNCADAPTER!? LOLWUT?  Well, you probably use it everyday… 5
    • THE BIG PICTURE – BASIC FLOW 6
    • THE BIG PICTURE – PUZZLES 7
    • PREREQUISITES TO CONSIDER  Network layer separation  Plain implementation  Sync status field for synced entities  Usually NOOP, Created, Updated & Deleted  Consider the field in UI flows  Consider partial sync  For better performance to sync only local delta 8
    • PUZZLES – ACCOUNT (1)  Key Features  Manage credentials;  Safe system store;  Multitenant support  Sync related  Token caching and invalidation  Alternative flow to login or sign in  Store extra data with account 9
    • PUZZLES – ACCOUNT (2)  Checklist:  Implement Authenticator  Implement Authentication Service  Define configuration in XML 10
    • PUZZLES – ACCOUNT (3)  Checklist:  Register Authentication Service in AndroidManifest  Add permissions  APIs to use:  android.accounts.AccountManager to work with accounts  android.accounts.Account to store credentials 11
    • PUZZLES – CONTENT PROVIDER (1)  Key features  Heart of DAO  Resource effective  Cursor, resource-effective scalability  Power of Joins  Built-in ListView refresh via ContentObserver & Cursor  Sync related  Acts as mediator for sync and UI layers  Supports automatic delta upload sync  NOTE: Can be fake one, but you’ll lose a lot of magic  12
    • PUZZLES – CONTENT PROVIDER (2)  Minimal implementation based on https://github.com/novoda/SQLiteProvider  Supports all CRUD  Supports DB versioning  And even more… 13
    • PUZZLES – SYNCADAPTER (1)  Key features  Plugin to Android SyncManager  SyncManager manages queue of execution  Adapter is executed in background thread & when network is available  Sync related  Scheduling & automated mode  Respects system settings  Can be overridden by manual request  Partial sync supported  Upload only local delta  Any other criteria (Bundle) 14
    • PUZZLES – SYNCADAPTER (2)  Checklist  Implement SyncAdapter class  Implement Sync Service  Define configuration xml 15
    • PUZZLES – SYNCADAPTER (3)  Checklist  Register Sync Service in AndroidManifest  Add permissions  APIs to use  android.content.ContentResolver to reach SyncManager programmatically 16
    • PUZZLES – SYNCADAPTER (4)  How to trigger sync?  Upload delta  ContentResolver.notifyChange  Be aware of cyclic calls if used in ContentProvider  Scheduling  ContentResolver.addPeriodicSync  Automated  ContentResolver.setSyncAutomatically  Manual  ContentResolver.requestSync  Manual forced  ContentResolver.requestSync  Pass SYNC_EXTRAS_MANUAL in bundle 17
    • THE BIG PICTURE – OPTIONAL PUZZLES 18
    • PROS & CONS  Pros  Simplify server interaction  A lot of work handled by framework  Resource effective – the Android way  Cons  A lot of puzzles, hard to start…  Lack of documentation  Error handling  Bugs  19
    • DOESANYBODYUSEIT? 20
    • DOCUMENTATION  Official docs  Great tutorial added in August ’13 http://developer.android.com/training/sync- adapters/index.html + code sample  Stackoverflow, use tags below  [android-syncadapter]  [sync] + [android] 21
    • BONUS: CODE SAMPLES  Repo on GitHub https://github.com/springbyexample/spring-by- example  Toy client-server app (both parties supplied )  Shows all puzzles implemented:  Accounts – fake one, there is no authentication  Content Provider based on novoda library  SyncAdapter logics  All wrapping XML configuration  Built via Maven  Follow README and be happy   Got questions?  a.kaverin@gmail.com 22
    • Q & A Thanks for your attention!23