SlideShare a Scribd company logo
1 of 23
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

More Related Content

What's hot

Introduction to Google App Engine
Introduction to Google App EngineIntroduction to Google App Engine
Introduction to Google App EngineAndrea Spadaccini
 
Discover Google Firebase Platform
Discover Google Firebase PlatformDiscover Google Firebase Platform
Discover Google Firebase PlatformSagar Mody
 
Google App Engine's Latest Features
Google App Engine's Latest FeaturesGoogle App Engine's Latest Features
Google App Engine's Latest FeaturesChris Schalk
 
Essential API Facade Patterns: Synchronous to Asynchronous Conversion (Episod...
Essential API Facade Patterns: Synchronous to Asynchronous Conversion (Episod...Essential API Facade Patterns: Synchronous to Asynchronous Conversion (Episod...
Essential API Facade Patterns: Synchronous to Asynchronous Conversion (Episod...Apigee | Google Cloud
 
Google App Engine
Google App EngineGoogle App Engine
Google App EngineCsaba Toth
 
What is Google App Engine
What is Google App EngineWhat is Google App Engine
What is Google App EngineChris Schalk
 
Inside Logic Apps
Inside Logic AppsInside Logic Apps
Inside Logic AppsBizTalk360
 
Cloud Computing Bootcamp On The Google App Engine v1.2.1
Cloud Computing Bootcamp On The Google App Engine v1.2.1Cloud Computing Bootcamp On The Google App Engine v1.2.1
Cloud Computing Bootcamp On The Google App Engine v1.2.1Matthew McCullough
 
Unleash the power of Serverless Computing
Unleash the power of Serverless ComputingUnleash the power of Serverless Computing
Unleash the power of Serverless ComputingGaurav Madaan
 
Google app engine
Google app engineGoogle app engine
Google app engineSuraj Mehta
 
Google App Engine: An Introduction
Google App Engine: An IntroductionGoogle App Engine: An Introduction
Google App Engine: An IntroductionAbu Ashraf Masnun
 
Developing Java Web Applications In Google App Engine
Developing Java Web Applications In Google App EngineDeveloping Java Web Applications In Google App Engine
Developing Java Web Applications In Google App EngineTahir Akram
 
Google app engine introduction
Google app engine introductionGoogle app engine introduction
Google app engine introductionrajsandhu1989
 
MuleSoft Surat Virtual Meetup#4 - Anypoint Monitoring and MuleSoft dataloader.io
MuleSoft Surat Virtual Meetup#4 - Anypoint Monitoring and MuleSoft dataloader.ioMuleSoft Surat Virtual Meetup#4 - Anypoint Monitoring and MuleSoft dataloader.io
MuleSoft Surat Virtual Meetup#4 - Anypoint Monitoring and MuleSoft dataloader.ioJitendra Bafna
 
Google App Engine - Overview #3
Google App Engine - Overview #3Google App Engine - Overview #3
Google App Engine - Overview #3Kay Kim
 
I've (probably) been using Google App Engine for a week longer than you have
I've (probably) been using Google App Engine for a week longer than you haveI've (probably) been using Google App Engine for a week longer than you have
I've (probably) been using Google App Engine for a week longer than you haveSimon Willison
 

What's hot (20)

Google Web Toolkit
Google Web ToolkitGoogle Web Toolkit
Google Web Toolkit
 
Google App Engine tutorial
Google App Engine tutorialGoogle App Engine tutorial
Google App Engine tutorial
 
Introduction to Google App Engine
Introduction to Google App EngineIntroduction to Google App Engine
Introduction to Google App Engine
 
Discover Google Firebase Platform
Discover Google Firebase PlatformDiscover Google Firebase Platform
Discover Google Firebase Platform
 
Google App Engine's Latest Features
Google App Engine's Latest FeaturesGoogle App Engine's Latest Features
Google App Engine's Latest Features
 
Essential API Facade Patterns: Synchronous to Asynchronous Conversion (Episod...
Essential API Facade Patterns: Synchronous to Asynchronous Conversion (Episod...Essential API Facade Patterns: Synchronous to Asynchronous Conversion (Episod...
Essential API Facade Patterns: Synchronous to Asynchronous Conversion (Episod...
 
Google App Engine
Google App EngineGoogle App Engine
Google App Engine
 
What is Google App Engine
What is Google App EngineWhat is Google App Engine
What is Google App Engine
 
Inside Logic Apps
Inside Logic AppsInside Logic Apps
Inside Logic Apps
 
Cloud Computing Bootcamp On The Google App Engine v1.2.1
Cloud Computing Bootcamp On The Google App Engine v1.2.1Cloud Computing Bootcamp On The Google App Engine v1.2.1
Cloud Computing Bootcamp On The Google App Engine v1.2.1
 
Android dev tips
Android dev tipsAndroid dev tips
Android dev tips
 
Unleash the power of Serverless Computing
Unleash the power of Serverless ComputingUnleash the power of Serverless Computing
Unleash the power of Serverless Computing
 
Google app engine
Google app engineGoogle app engine
Google app engine
 
Firebase
FirebaseFirebase
Firebase
 
Google App Engine: An Introduction
Google App Engine: An IntroductionGoogle App Engine: An Introduction
Google App Engine: An Introduction
 
Developing Java Web Applications In Google App Engine
Developing Java Web Applications In Google App EngineDeveloping Java Web Applications In Google App Engine
Developing Java Web Applications In Google App Engine
 
Google app engine introduction
Google app engine introductionGoogle app engine introduction
Google app engine introduction
 
MuleSoft Surat Virtual Meetup#4 - Anypoint Monitoring and MuleSoft dataloader.io
MuleSoft Surat Virtual Meetup#4 - Anypoint Monitoring and MuleSoft dataloader.ioMuleSoft Surat Virtual Meetup#4 - Anypoint Monitoring and MuleSoft dataloader.io
MuleSoft Surat Virtual Meetup#4 - Anypoint Monitoring and MuleSoft dataloader.io
 
Google App Engine - Overview #3
Google App Engine - Overview #3Google App Engine - Overview #3
Google App Engine - Overview #3
 
I've (probably) been using Google App Engine for a week longer than you have
I've (probably) been using Google App Engine for a week longer than you haveI've (probably) been using Google App Engine for a week longer than you have
I've (probably) been using Google App Engine for a week longer than you have
 

Similar to Developing Android Client Apps via SyncAdapter

Campus portal for wireless devices srs
Campus portal for wireless devices srsCampus portal for wireless devices srs
Campus portal for wireless devices srsAnand Goyal
 
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 LavoieVMware Tanzu
 
Cloud-native Java EE-volution
Cloud-native Java EE-volutionCloud-native Java EE-volution
Cloud-native Java EE-volutionQAware GmbH
 
Device APIs at TakeOff Conference
Device APIs at TakeOff ConferenceDevice APIs at TakeOff Conference
Device APIs at TakeOff Conferencedianacheng
 
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...VMware Tanzu
 
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 - BostonVMware Tanzu
 
ANDROID presentation prabal
ANDROID presentation prabalANDROID presentation prabal
ANDROID presentation prabalPrabal Tyagi
 
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 2017Patrick Chanezon
 
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 designKyrylo Reznykov
 
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 NImam Raza
 
OpenShift Taiwan Vol.1 Technology Overview
OpenShift Taiwan Vol.1 Technology OverviewOpenShift Taiwan Vol.1 Technology Overview
OpenShift Taiwan Vol.1 Technology OverviewJason Peng
 
Cross Platform Mobile Technologies
Cross Platform Mobile TechnologiesCross Platform Mobile Technologies
Cross Platform Mobile TechnologiesTalentica Software
 
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...Convertigo | MADP & MBaaS
 
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 appsRakuten Group, Inc.
 
"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...Fwdays
 
Rhomobile 5.5 Release Notes
Rhomobile 5.5 Release NotesRhomobile 5.5 Release Notes
Rhomobile 5.5 Release NotesKonstantin Rybas
 
"Wie passen Serverless & Autonomous zusammen?"
"Wie passen Serverless & Autonomous zusammen?""Wie passen Serverless & Autonomous zusammen?"
"Wie passen Serverless & Autonomous zusammen?"Volker Linz
 
OSMC 2022 | Current State of icinga by Bernd Erk
OSMC 2022 | Current State of icinga by Bernd ErkOSMC 2022 | Current State of icinga by Bernd Erk
OSMC 2022 | Current State of icinga by Bernd ErkNETWAYS
 

Similar to Developing Android Client Apps via SyncAdapter (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
 
Cloud-native Java EE-volution
Cloud-native Java EE-volutionCloud-native Java EE-volution
Cloud-native Java EE-volution
 
Device APIs at TakeOff Conference
Device APIs at TakeOff ConferenceDevice APIs at TakeOff Conference
Device APIs at TakeOff Conference
 
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...
 
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
 
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
 
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
 
OpenShift Taiwan Vol.1 Technology Overview
OpenShift Taiwan Vol.1 Technology OverviewOpenShift Taiwan Vol.1 Technology Overview
OpenShift Taiwan Vol.1 Technology Overview
 
Cross Platform Mobile Technologies
Cross Platform Mobile TechnologiesCross Platform Mobile Technologies
Cross Platform Mobile Technologies
 
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
 
"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...
 
Rhomobile 5.5 Release Notes
Rhomobile 5.5 Release NotesRhomobile 5.5 Release Notes
Rhomobile 5.5 Release Notes
 
"Wie passen Serverless & Autonomous zusammen?"
"Wie passen Serverless & Autonomous zusammen?""Wie passen Serverless & Autonomous zusammen?"
"Wie passen Serverless & Autonomous zusammen?"
 
OSMC 2022 | Current State of icinga by Bernd Erk
OSMC 2022 | Current State of icinga by Bernd ErkOSMC 2022 | Current State of icinga by Bernd Erk
OSMC 2022 | Current State of icinga by Bernd Erk
 

Recently uploaded

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksSoftradix Technologies
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 

Recently uploaded (20)

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Benefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other FrameworksBenefits Of Flutter Compared To Other Frameworks
Benefits Of Flutter Compared To Other Frameworks
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 

Developing Android Client Apps via SyncAdapter

  • 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

Editor's Notes

  1. Introduction. Ask about Android experience, client-server apps and sync adapter knowledge. Session goal.
  2. Define session format – ask questions on current slide content. Complex & conceptual question – Q&A block.
  3. Persisting in cache – Evernote example;off-line mode - no network; capability to create/delete/edit data offline and changes to be applied when back online
  4. What we need to consider to achieve functionality we just mentioned…Network availability – check net before requestPending queue – gather requests if offline, avoid duplicated requests to save battery, like several refreshes, or some upload requests;
  5. Rotation symbol near wifi in HTC Sense;Accounts; Configuration for Google services; Multiple accounts!
  6. Basic flow suggested by the framework; All UI works only with Content Provider; Sync Adapter works with CP;
  7. Let’s see the same picture, but mentioning puzzles we’ll have to implement – 3 items;
  8. Network will be used in 3 places – Login activity, Authenticator – token routines, SyncAdapter network operations;You logic should allow to separate upload from download, as well as an option – to separate synced entities. For example: facebook, sync news, but not contacts at the same time;
  9. How you usually store your app credentials? Prefs or DB? Prefs fine till you got multiple accounts; both pretty safe;Account can have username, password and extra data associated;
  10. Only 2 classes, 1 is almost a dumbstub
  11. Usually CP are avoided, I’m not sure why? ORM fashion?Cursor – allows Android to manage window + fetch exact fields and not whole entity; avoid Cursor to entity mapping when not needed;Joins can allow to do effective cross entity fetch;
  12. DB versioning based on sql file names;
  13. All you code is executed when network is on – but you should be aware that it can be interrupted; Use Sync status to allow repeatable requests;Schedule time intervals, not exact time; intervals may vary;
  14. 2 classes, service – is almost a stub; but it is advised to make creation of syncadapter thread safeisAlwaysSyncable – important to make sure it is synced when network available;
  15. notifyChange is usually used from Content Provider;
  16. If you have existing app – it may be wise to drop some of components;Account and ContentProvider can be implemented as stubs; but they must be registered;
  17. Simple – no need to manage threading, define IntentServices, thing of UI callbacks, etc.Framework provides - network check, queue, duplicated requests, etc;Resource – global queue, no channel starvation;Error handling, hard & soft errorsBugs – invalidate tokens; some sync flags ignored. When it works – it’s stable;
  18. Any.do – switched a month ago; Evernote – in June-July.
  19. Stackoverflow compensates lack of docs;