SlideShare uma empresa Scribd logo
1 de 23
Baixar para ler offline
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

Mais conteúdo relacionado

Mais procurados

mdevcon - A Primer to SyncAdapters
mdevcon  - A Primer to SyncAdaptersmdevcon  - A Primer to SyncAdapters
mdevcon - A Primer to SyncAdapters
Kiana Tennyson
 

Mais procurados (20)

Nyc mule soft_meetup_13_march_2021
Nyc mule soft_meetup_13_march_2021Nyc mule soft_meetup_13_march_2021
Nyc mule soft_meetup_13_march_2021
 
First Look at Azure Logic Apps (BAUG)
First Look at Azure Logic Apps (BAUG)First Look at Azure Logic Apps (BAUG)
First Look at Azure Logic Apps (BAUG)
 
Vaadin codemotion 2014
Vaadin codemotion 2014Vaadin codemotion 2014
Vaadin codemotion 2014
 
Connector API Apps
Connector API AppsConnector API Apps
Connector API Apps
 
日本開發者大會短講分享
日本開發者大會短講分享日本開發者大會短講分享
日本開發者大會短講分享
 
WebSphere Connect and API Discovery
WebSphere Connect and API DiscoveryWebSphere Connect and API Discovery
WebSphere Connect and API Discovery
 
MuleSoft Surat Live Demonstration Virtual Meetup#4 - Automate Anypoint VPC, V...
MuleSoft Surat Live Demonstration Virtual Meetup#4 - Automate Anypoint VPC, V...MuleSoft Surat Live Demonstration Virtual Meetup#4 - Automate Anypoint VPC, V...
MuleSoft Surat Live Demonstration Virtual Meetup#4 - Automate Anypoint VPC, V...
 
Cloud Native Java with Spring Cloud Services
Cloud Native Java with Spring Cloud ServicesCloud Native Java with Spring Cloud Services
Cloud Native Java with Spring Cloud Services
 
Meteor Introduction - Ashish
Meteor Introduction - AshishMeteor Introduction - Ashish
Meteor Introduction - Ashish
 
Building a Lightning App with Angular Material Design
Building a Lightning App with Angular Material DesignBuilding a Lightning App with Angular Material Design
Building a Lightning App with Angular Material Design
 
Development Process Optimization Using Docker. Based on a True Story
Development Process Optimization Using Docker. Based on a True StoryDevelopment Process Optimization Using Docker. Based on a True Story
Development Process Optimization Using Docker. Based on a True Story
 
Securing SharePoint Apps with OAuth
Securing SharePoint Apps with OAuthSecuring SharePoint Apps with OAuth
Securing SharePoint Apps with OAuth
 
Inside Logic Apps
Inside Logic AppsInside Logic Apps
Inside Logic Apps
 
[WSO2Con Asia 2018] Managing API Integrations with WSO2 API Manager
[WSO2Con Asia 2018] Managing API Integrations with WSO2 API Manager[WSO2Con Asia 2018] Managing API Integrations with WSO2 API Manager
[WSO2Con Asia 2018] Managing API Integrations with WSO2 API Manager
 
Android CI and Appium
Android CI and AppiumAndroid CI and Appium
Android CI and Appium
 
Deploying applications to Cloud with Google App Engine
Deploying applications to Cloud with Google App EngineDeploying applications to Cloud with Google App Engine
Deploying applications to Cloud with Google App Engine
 
Unleash the power of Serverless Computing
Unleash the power of Serverless ComputingUnleash the power of Serverless Computing
Unleash the power of Serverless Computing
 
Build a REST API for your Mobile Apps using Node.js
Build a REST API for your Mobile Apps using Node.jsBuild a REST API for your Mobile Apps using Node.js
Build a REST API for your Mobile Apps using Node.js
 
Google app engine by example
Google app engine by exampleGoogle app engine by example
Google app engine by example
 
mdevcon - A Primer to SyncAdapters
mdevcon  - A Primer to SyncAdaptersmdevcon  - A Primer to SyncAdapters
mdevcon - A Primer to SyncAdapters
 

Destaque

Android ui adapter
Android ui adapterAndroid ui adapter
Android ui adapter
Krazy Koder
 
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
Nehil Jain
 
Adapter & ListView & ExpandalbeListView
Adapter & ListView & ExpandalbeListViewAdapter & ListView & ExpandalbeListView
Adapter & ListView & ExpandalbeListView
Yuki Anzai
 

Destaque (13)

Sync on Android
Sync on AndroidSync on Android
Sync on Android
 
Android ui adapter
Android ui adapterAndroid ui adapter
Android ui adapter
 
Android adapters
Android adaptersAndroid adapters
Android adapters
 
SyncAdapter, Sincronização de dados no Android
SyncAdapter, Sincronização de dados no AndroidSyncAdapter, Sincronização de dados no Android
SyncAdapter, Sincronização de dados no Android
 
Inside the Android AccountManager
Inside the Android AccountManagerInside the Android AccountManager
Inside the Android AccountManager
 
Adapter and cache technique
Adapter and cache techniqueAdapter and cache technique
Adapter and cache technique
 
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
 
Android Training (AdapterView & Adapter)
Android Training (AdapterView & Adapter)Android Training (AdapterView & Adapter)
Android Training (AdapterView & Adapter)
 
Command and Adapter Pattern
Command and Adapter PatternCommand and Adapter Pattern
Command and Adapter Pattern
 
Android development - ListView & Adapter
Android development - ListView & AdapterAndroid development - ListView & Adapter
Android development - ListView & Adapter
 
Adapter & ListView & ExpandalbeListView
Adapter & ListView & ExpandalbeListViewAdapter & ListView & ExpandalbeListView
Adapter & ListView & ExpandalbeListView
 
Design Patterns - 04 Adapter and Facade Pattern
Design Patterns - 04 Adapter and Facade PatternDesign Patterns - 04 Adapter and Facade Pattern
Design Patterns - 04 Adapter and Facade Pattern
 
Adapter Design Pattern
Adapter Design PatternAdapter Design Pattern
Adapter Design Pattern
 

Semelhante a Android sync adapter

ANDROID presentation prabal
ANDROID presentation prabalANDROID presentation prabal
ANDROID presentation prabal
Prabal Tyagi
 

Semelhante a Android sync adapter (20)

Campus portal for wireless devices srs
Campus portal for wireless devices srsCampus portal for wireless devices srs
Campus portal for wireless devices srs
 
Spring Boot & Spring Cloud Apps on Pivotal Application Service - Daniel Lavoie
Spring Boot & Spring Cloud Apps on Pivotal Application Service - Daniel LavoieSpring Boot & Spring Cloud Apps on Pivotal Application Service - Daniel Lavoie
Spring Boot & Spring Cloud Apps on Pivotal Application Service - Daniel Lavoie
 
Android Anatomy
Android  AnatomyAndroid  Anatomy
Android Anatomy
 
Device APIs at TakeOff Conference
Device APIs at TakeOff ConferenceDevice APIs at TakeOff Conference
Device APIs at TakeOff Conference
 
Cloud-native Java EE-volution
Cloud-native Java EE-volutionCloud-native Java EE-volution
Cloud-native Java EE-volution
 
SpringOne Tour Denver - Spring Boot & Spring Cloud on Pivotal Application Ser...
SpringOne Tour Denver - Spring Boot & Spring Cloud on Pivotal Application Ser...SpringOne Tour Denver - Spring Boot & Spring Cloud on Pivotal Application Ser...
SpringOne Tour Denver - Spring Boot & Spring Cloud on Pivotal Application Ser...
 
GDG Devfest 2016 session on Android N
GDG Devfest 2016 session on Android NGDG Devfest 2016 session on Android N
GDG Devfest 2016 session on Android N
 
Spring and Pivotal Application Service - SpringOne Tour - Boston
Spring and Pivotal Application Service - SpringOne Tour - BostonSpring and Pivotal Application Service - SpringOne Tour - Boston
Spring and Pivotal Application Service - SpringOne Tour - Boston
 
OpenShift Taiwan Vol.1 Technology Overview
OpenShift Taiwan Vol.1 Technology OverviewOpenShift Taiwan Vol.1 Technology Overview
OpenShift Taiwan Vol.1 Technology Overview
 
ANDROID presentation prabal
ANDROID presentation prabalANDROID presentation prabal
ANDROID presentation prabal
 
What's New in Docker - February 2017
What's New in Docker - February 2017What's New in Docker - February 2017
What's New in Docker - February 2017
 
Raising ux bar with offline first design
Raising ux bar with offline first designRaising ux bar with offline first design
Raising ux bar with offline first design
 
Android session-1-sajib
Android session-1-sajibAndroid session-1-sajib
Android session-1-sajib
 
Cross Platform Mobile Technologies
Cross Platform Mobile TechnologiesCross Platform Mobile Technologies
Cross Platform Mobile Technologies
 
Rhomobile 5.5 Release Notes
Rhomobile 5.5 Release NotesRhomobile 5.5 Release Notes
Rhomobile 5.5 Release Notes
 
Convertigo Mobility Platform | Mobile Application Development for Enterprises...
Convertigo Mobility Platform | Mobile Application Development for Enterprises...Convertigo Mobility Platform | Mobile Application Development for Enterprises...
Convertigo Mobility Platform | Mobile Application Development for Enterprises...
 
Let's talk about the future: state-of-the-art mobile web & hybrid apps
Let's talk about the future: state-of-the-art mobile web & hybrid appsLet's talk about the future: state-of-the-art mobile web & hybrid apps
Let's talk about the future: state-of-the-art mobile web & hybrid apps
 
Campus portal for wireless devices
Campus portal for wireless devicesCampus portal for wireless devices
Campus portal for wireless devices
 
"Wie passen Serverless & Autonomous zusammen?"
"Wie passen Serverless & Autonomous zusammen?""Wie passen Serverless & Autonomous zusammen?"
"Wie passen Serverless & Autonomous zusammen?"
 
"Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai...
"Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai..."Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai...
"Micro-frontends: Scalable and Modular Frontend in Parimatch Tech", Kyrylo Ai...
 

Mais de Alex Tumanoff

Navigation map factory by Alexey Klimenko
Navigation map factory by Alexey KlimenkoNavigation map factory by Alexey Klimenko
Navigation map factory by Alexey Klimenko
Alex Tumanoff
 
Serialization and performance by Sergey Morenets
Serialization and performance by Sergey MorenetsSerialization and performance by Sergey Morenets
Serialization and performance by Sergey Morenets
Alex Tumanoff
 
Async clinic by by Sergey Teplyakov
Async clinic by by Sergey TeplyakovAsync clinic by by Sergey Teplyakov
Async clinic by by Sergey Teplyakov
Alex Tumanoff
 
Deep Dive C# by Sergey Teplyakov
Deep Dive  C# by Sergey TeplyakovDeep Dive  C# by Sergey Teplyakov
Deep Dive C# by Sergey Teplyakov
Alex Tumanoff
 
Bdd by Dmitri Aizenberg
Bdd by Dmitri AizenbergBdd by Dmitri Aizenberg
Bdd by Dmitri Aizenberg
Alex Tumanoff
 
Разработка расширений Firefox
Разработка расширений FirefoxРазработка расширений Firefox
Разработка расширений Firefox
Alex Tumanoff
 

Mais de Alex Tumanoff (20)

Sql server 2019 New Features by Yevhen Nedaskivskyi
Sql server 2019 New Features by Yevhen NedaskivskyiSql server 2019 New Features by Yevhen Nedaskivskyi
Sql server 2019 New Features by Yevhen Nedaskivskyi
 
Odessa .net-user-group-sql-server-2019-hidden-gems by Denis Reznik
Odessa .net-user-group-sql-server-2019-hidden-gems by Denis ReznikOdessa .net-user-group-sql-server-2019-hidden-gems by Denis Reznik
Odessa .net-user-group-sql-server-2019-hidden-gems by Denis Reznik
 
Azure data bricks by Eugene Polonichko
Azure data bricks by Eugene PolonichkoAzure data bricks by Eugene Polonichko
Azure data bricks by Eugene Polonichko
 
Sdlc by Anatoliy Anthony Cox
Sdlc by  Anatoliy Anthony CoxSdlc by  Anatoliy Anthony Cox
Sdlc by Anatoliy Anthony Cox
 
Kostenko ux november-2014_1
Kostenko ux november-2014_1Kostenko ux november-2014_1
Kostenko ux november-2014_1
 
Java 8 in action.jinq.v.1.3
Java 8 in action.jinq.v.1.3Java 8 in action.jinq.v.1.3
Java 8 in action.jinq.v.1.3
 
"Drools: декларативная бизнес-логика в Java-приложениях" by Дмитрий Контрерас...
"Drools: декларативная бизнес-логика в Java-приложениях" by Дмитрий Контрерас..."Drools: декларативная бизнес-логика в Java-приложениях" by Дмитрий Контрерас...
"Drools: декларативная бизнес-логика в Java-приложениях" by Дмитрий Контрерас...
 
Spring.new hope.1.3
Spring.new hope.1.3Spring.new hope.1.3
Spring.new hope.1.3
 
Sql saturday azure storage by Anton Vidishchev
Sql saturday azure storage by Anton VidishchevSql saturday azure storage by Anton Vidishchev
Sql saturday azure storage by Anton Vidishchev
 
Navigation map factory by Alexey Klimenko
Navigation map factory by Alexey KlimenkoNavigation map factory by Alexey Klimenko
Navigation map factory by Alexey Klimenko
 
Serialization and performance by Sergey Morenets
Serialization and performance by Sergey MorenetsSerialization and performance by Sergey Morenets
Serialization and performance by Sergey Morenets
 
Игры для мобильных платформ by Алексей Рыбаков
Игры для мобильных платформ by Алексей РыбаковИгры для мобильных платформ by Алексей Рыбаков
Игры для мобильных платформ by Алексей Рыбаков
 
Async clinic by by Sergey Teplyakov
Async clinic by by Sergey TeplyakovAsync clinic by by Sergey Teplyakov
Async clinic by by Sergey Teplyakov
 
Deep Dive C# by Sergey Teplyakov
Deep Dive  C# by Sergey TeplyakovDeep Dive  C# by Sergey Teplyakov
Deep Dive C# by Sergey Teplyakov
 
Bdd by Dmitri Aizenberg
Bdd by Dmitri AizenbergBdd by Dmitri Aizenberg
Bdd by Dmitri Aizenberg
 
Неформальные размышления о сертификации в IT
Неформальные размышления о сертификации в ITНеформальные размышления о сертификации в IT
Неформальные размышления о сертификации в IT
 
Разработка расширений Firefox
Разработка расширений FirefoxРазработка расширений Firefox
Разработка расширений Firefox
 
"AnnotatedSQL - провайдер с плюшками за 5 минут" - Геннадий Дубина, Senior So...
"AnnotatedSQL - провайдер с плюшками за 5 минут" - Геннадий Дубина, Senior So..."AnnotatedSQL - провайдер с плюшками за 5 минут" - Геннадий Дубина, Senior So...
"AnnotatedSQL - провайдер с плюшками за 5 минут" - Геннадий Дубина, Senior So...
 
Patterns of parallel programming
Patterns of parallel programmingPatterns of parallel programming
Patterns of parallel programming
 
Lambda выражения и Java 8
Lambda выражения и Java 8Lambda выражения и Java 8
Lambda выражения и Java 8
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Último (20)

2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024Manulife - Insurer Transformation Award 2024
Manulife - Insurer Transformation Award 2024
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
Web Form Automation for Bonterra Impact Management (fka Social Solutions Apri...
 

Android sync adapter

  • 1. DEVELOPING ANDROID CLIENT APPS VIA SYNCADAPTER Anatoliy Kaverin Lohika @ 2013
  • 2. SESSION AGENDA  Why?  SyncAdapter!? LOLWUT?  The big picture  Puzzles  Does anybody use it?  Code samples, documentation  Q&A 2
  • 4. 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
  • 5. SYNCADAPTER!? LOLWUT?  Well, you probably use it everyday… 5
  • 6. THE BIG PICTURE – BASIC FLOW 6
  • 7. THE BIG PICTURE – PUZZLES 7
  • 8. 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
  • 9. 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
  • 10. PUZZLES – ACCOUNT (2)  Checklist:  Implement Authenticator  Implement Authentication Service  Define configuration in XML 10
  • 11. 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
  • 12. 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
  • 13. PUZZLES – CONTENT PROVIDER (2)  Minimal implementation based on https://github.com/novoda/SQLiteProvider  Supports all CRUD  Supports DB versioning  And even more… 13
  • 14. 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
  • 15. PUZZLES – SYNCADAPTER (2)  Checklist  Implement SyncAdapter class  Implement Sync Service  Define configuration xml 15
  • 16. PUZZLES – SYNCADAPTER (3)  Checklist  Register Sync Service in AndroidManifest  Add permissions  APIs to use  android.content.ContentResolver to reach SyncManager programmatically 16
  • 17. 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
  • 18. THE BIG PICTURE – OPTIONAL PUZZLES 18
  • 19. 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
  • 21. 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
  • 22. 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
  • 23. Q & A Thanks for your attention!23