SlideShare uma empresa Scribd logo
1 de 83
Baixar para ler offline
Sync              ON ANDROID


Jerzy Chalupski
chalup
jerzy@futuresimple.com
What we do in general...
What we do ALL THE TIME




                          sync, sync, sync, sync
Sync     ON ANDROID




   OVERVIEW                ARCHITECTURE

CONTENT PROVIDER         PITFALLS & PROTIPS
Sync     ON ANDROID




   OVERVIEW                ARCHITECTURE

CONTENT PROVIDER         PITFALLS & PROTIPS
Not exactly the fresh topic...




        „Developing Android REST client
        applications”
                                     by Virgil Dobjanschi
                                       @Google I/O 2010
Not exactly the fresh topic...




        „Synchronizacja danych z serwisami
        webowymi w Androidzie”
                                   by Bartosz Filipowicz
                                       @KrakDroid 2011
Not exactly the fresh topic...




        „Synchronizacja danych z serwisami
        webowymi w Androidzie”
                                       by Bartosz Filipowicz
                                           @KrakDroid 2011




                        ...but there is still much confusion
AccountManager
 SyncManager
                  UI     Authenticator

ContentProvider
                          SyncAdapter
    ContentResolver
„Wat? Why do I need to write
all this crap, sync is just
fetching data from server”
                         typical reaction
Sync provides data sharing
Sync provides data sharing
             offline mode
Sync provides data sharing
             offline mode
             responsive UI
Sync provides data sharing
             offline mode
             responsive UI

              GREAT UX
Sync     ON ANDROID




   OVERVIEW                ARCHITECTURE

CONTENT PROVIDER         PITFALLS & PROTIPS
ContentProvider 101: CRUD



       CREATE               insert()


       READ                 query()


       UPDATE               update()


       DELETE               delete()
ContentProvider 101: URI




       content://com.futuresimple.krakdroid.Provider/datasets/1
ContentProvider 101: URI




       content://com.futuresimple.krakdroid.Provider/datasets/1
ContentProvider 101: URI




       content://com.futuresimple.krakdroid.Provider/datasets/1
ContentProvider 101: URI




       content://com.futuresimple.krakdroid.Provider/datasets/1
ContentProvider 101: notifications




       content://com.futuresimple.krakdroid.Provider/datasets/1
       content://com.futuresimple.krakdroid.Provider/solutions
       content://com.futuresimple.krakdroid.Provider/solutions/1
       content://com.futuresimple.krakdroid.Provider/solutions/1/answers/1
       content://com.futuresimple.krakdroid.Provider/solutions/1/answers/2
       content://com.futuresimple.krakdroid.Provider/solutions/2/answers/1
ContentProvider 101: notifications




       content://com.futuresimple.krakdroid.Provider/datasets/1
       content://com.futuresimple.krakdroid.Provider/solutions
       content://com.futuresimple.krakdroid.Provider/solutions/1
       content://com.futuresimple.krakdroid.Provider/solutions/1/answers/1
       content://com.futuresimple.krakdroid.Provider/solutions/1/answers/2
       content://com.futuresimple.krakdroid.Provider/solutions/2/answers/1


           ContentResolver.notifyChange(“content://
       com.futuresimple.krakdroid.Provider/datasets/1”);
ContentProvider 101: notifications




        content://com.futuresimple.krakdroid.Provider/datasets/1
        content://com.futuresimple.krakdroid.Provider/solutions
        content://com.futuresimple.krakdroid.Provider/solutions/1
        content://com.futuresimple.krakdroid.Provider/solutions/1/answers/1
        content://com.futuresimple.krakdroid.Provider/solutions/1/answers/2
        content://com.futuresimple.krakdroid.Provider/solutions/2/answers/1


             ContentResolver.notifyChange(“content://
   com.futuresimple.krakdroid.Provider/solutions/1/answers/1”);
Sync     ON ANDROID




   OVERVIEW                ARCHITECTURE

CONTENT PROVIDER         PITFALLS & PROTIPS
AccountManager
 SyncManager
                  UI     Authenticator

ContentProvider
                          SyncAdapter
    ContentResolver
Authenticator                   Sync architecture
                                    CREATING NEW ACCOUNT




AccountManager
        addAccount()


                       UI

 SyncManager                ContentResolver



 SyncAdapter                ContentProvider
Authenticator                   Sync architecture
                                    CREATING NEW ACCOUNT
        addAccount()




AccountManager
        addAccount()


                       UI

 SyncManager                ContentResolver



 SyncAdapter                ContentProvider
Authenticator                   Sync architecture
                                    CREATING NEW ACCOUNT
        addAccount()




AccountManager
        addAccount()


                       UI

 SyncManager                ContentResolver



 SyncAdapter                ContentProvider
Authenticator             Sync architecture
                                    SHOW SYNCED DATA




AccountManager

                 UI
                              query()




 SyncManager          ContentResolver

                              query()




 SyncAdapter          ContentProvider
Authenticator                          Sync architecture
                                                 REQUEST SYNC




AccountManager
        getAccountsByType()


                              UI

 SyncManager                       ContentResolver



 SyncAdapter                       ContentProvider
Authenticator                          Sync architecture
                                                       REQUEST SYNC




AccountManager
        getAccountsByType()


                              UI           requestSync()




 SyncManager                       ContentResolver



 SyncAdapter                       ContentProvider
Authenticator                                  Sync architecture
                                                                 REQUEST SYNC




AccountManager
                  getAccountsByType()


                                        UI           requestSync()




   SyncManager                               ContentResolver

onPerformSync()




   SyncAdapter                               ContentProvider
Authenticator             Sync architecture
                                             EDIT DATA




AccountManager

                 UI               insert()




 SyncManager          ContentResolver

                                  insert()




 SyncAdapter          ContentProvider
Authenticator                         Sync architecture
                                                         EDIT DATA




AccountManager

                 UI                           insert()




 SyncManager                  ContentResolver

                      notifyChange()          insert()




 SyncAdapter                  ContentProvider
Authenticator                         Sync architecture
                                                         EDIT DATA




AccountManager

                 UI                           insert()




 SyncManager                  ContentResolver

                      notifyChange()          insert()




 SyncAdapter                  ContentProvider
Authenticator                                      Sync architecture
                                                                      EDIT DATA




AccountManager

        getAccountsByType()
                              UI                           insert()




 SyncManager                               ContentResolver

                                   notifyChange()          insert()




 SyncAdapter                               ContentProvider
Authenticator                                              Sync architecture
                                                                                EDIT DATA




AccountManager

                  getAccountsByType()
                                        UI                           insert()




   SyncManager                                       ContentResolver

onPerformSync()                              notifyChange()          insert()




   SyncAdapter                                       ContentProvider
Authenticator             Sync architecture
                                     POST NEW DATA




AccountManager

                   UI

   SyncManager          ContentResolver

onPerformSync()




   SyncAdapter          ContentProvider
Authenticator                             Sync architecture
                                                     POST NEW DATA
                  getAuthToken()




AccountManager

                                   UI

   SyncManager                          ContentResolver

onPerformSync()




   SyncAdapter                          ContentProvider
Authenticator                                  Sync architecture
                                                           POST NEW DATA
                  getAuthToken()




AccountManager

                                        UI

   SyncManager                               ContentResolver
                                   query()
onPerformSync()                                          query()




   SyncAdapter                               ContentProvider
Authenticator                                         Sync architecture
                                                                  POST NEW DATA
                  getAuthToken()




AccountManager

                                               UI

   SyncManager                                      ContentResolver
                                          query()
onPerformSync()                                                 query()




   SyncAdapter                     POST
                                                    ContentProvider
Authenticator             Sync architecture
                                     GET NEW DATA




AccountManager

                   UI

   SyncManager          ContentResolver

onPerformSync()




   SyncAdapter          ContentProvider
Authenticator                             Sync architecture
                                                     GET NEW DATA
                  getAuthToken()




AccountManager

                                   UI

   SyncManager                          ContentResolver

onPerformSync()




   SyncAdapter                          ContentProvider
Authenticator                                   Sync architecture
                                                           GET NEW DATA
                  getAuthToken()




AccountManager

                                         UI

   SyncManager                                ContentResolver

onPerformSync()




   SyncAdapter                     GET
                                              ContentProvider
Authenticator                                             Sync architecture
                                                                     GET NEW DATA
                  getAuthToken()




AccountManager

                                             UI

   SyncManager                                      ContentResolver
                                     applyBatch()
onPerformSync()

                                                     applyBatch()




   SyncAdapter                     GET
                                                    ContentProvider
Authenticator                                             Sync architecture
                                                                       GET NEW DATA
                  getAuthToken()




AccountManager

                                             UI

   SyncManager                                      ContentResolver
                                     applyBatch()
onPerformSync()                                                     notifyChange()

                                                     applyBatch()




   SyncAdapter                     GET
                                                    ContentProvider
Authenticator                                               Sync architecture
                                                                            GET NEW DATA
                  getAuthToken()




AccountManager

                                                    onLoaderFinished()
                                             UI

   SyncManager                                      ContentResolver
                                     applyBatch()
onPerformSync()                                                          notifyChange()

                                                       applyBatch()




   SyncAdapter                     GET
                                                    ContentProvider
Authenticator             Sync architecture
                            WIN #1: NO REMOTE I/O IN UI




AccountManager

                 UI

 SyncManager          ContentResolver



 SyncAdapter          ContentProvider
Authenticator             Sync architecture
                             WIN #2: SYNC SCHEDULING




AccountManager

                 UI

 SyncManager          ContentResolver



 SyncAdapter          ContentProvider
Sync     ON ANDROID




   OVERVIEW                ARCHITECTURE

CONTENT PROVIDER         PITFALLS & PROTIPS
IDs in ContentProvider URIs


      content://com.futuresimple.krakdroid.Provider/datasets/1
IDs in ContentProvider URIs


      content://com.futuresimple.krakdroid.Provider/datasets/1




  Plan A: Use local IDs! (BaseColumns._ID)
IDs in ContentProvider URIs


      content://com.futuresimple.krakdroid.Provider/datasets/1




  Plan A: Use local IDs! (BaseColumns._ID)



  ISSUE: still need server-side IDs for relations
IDs in ContentProvider URIs


      content://com.futuresimple.krakdroid.Provider/datasets/1




  Plan A: Use local IDs! (BaseColumns._ID)



  ISSUE: still need server-side IDs for relations
  ISSUE: conversions between server and local IDs
IDs in ContentProvider URIs


   content://com.futuresimple.krakdroid.Provider/datasets/15002900




  Plan B: OK, use server-side IDs!
IDs in ContentProvider URIs


   content://com.futuresimple.krakdroid.Provider/datasets/15002900




  Plan B: OK, use server-side IDs!



  ISSUE: what about offline mode?
IDs in ContentProvider URIs


  content://com.futuresimple.krakdroid.Provider/datasets/-42
  content://com.futuresimple.krakdroid.Provider/datasets/15002900


  Plan C: OK, let’s mix things up!
IDs in ContentProvider URIs


  content://com.futuresimple.krakdroid.Provider/datasets/-42
  content://com.futuresimple.krakdroid.Provider/datasets/15002900


  Plan C: OK, let’s mix things up!



  ISSUE: very tricky implementation
IDs in ContentProvider URIs


     content://com.futuresimple.krakdroid.Provider/datasets/GUID




  Plan D: GUID
IDs in ContentProvider URIs


     content://com.futuresimple.krakdroid.Provider/datasets/GUID




  Plan D: GUID



  ISSUE: needs support on the backend
ContentResolver requestSync() vs. notifyChange()




      requestSync(account, authority, extras)

      notifyChange(uri, observer, syncToNetwork)
ContentResolver requestSync() vs. notifyChange()




      requestSync(account, authority, extras)

      notifyChange(uri, observer, syncToNetwork)
Deleting an account




      From your app

      From system settings

      From 3rd party app
Deleting an account




      From your app
                             “Where should I
      From system settings     perform user
                              data cleanup?”
      From 3rd party app
Deleting an account




  @Override getAccountRemovalAllowed()
Deleting an account




  @Override getAccountRemovalAllowed()



  CONS: depends on current Settings implementation.
  PROS: exactly the thing you need.
Deleting an account



  <receiver
      android:name=".auth.AccountBroadcastReceiver"
      android:enabled="true" >
      <intent-filter>
          <action android:name="android.accounts.LOGIN_ACCOUNTS_CHANGED" />
      </intent-filter>
  </receiver>
Deleting an account



  <receiver
      android:name=".auth.AccountBroadcastReceiver"
      android:enabled="true" >
      <intent-filter>
          <action android:name="android.accounts.LOGIN_ACCOUNTS_CHANGED" />
      </intent-filter>
  </receiver>




  CONS: only info about existing accounts.
  PROS: peace of mind.
Sync lifecycle


   Happy case:
Sync lifecycle


   Happy case:




            requestSync()
Sync lifecycle


   Happy case:


                    onPerformSync()

            requestSync()
Sync lifecycle


   Happy case:


                    onPerformSync()

            requestSync()   onStatusChanged()
Sync lifecycle


   Not-so-happy case:


                    onPerformSync()

            requestSync()   onStatusChanged()
Sync lifecycle


   Not-so-happy case:


                   onPerformSync()

   requestSync()           onStatusChanged()
Sync lifecycle


   Not-so-happy case:


                   onPerformSync()

   requestSync()           cancelSync()
                                +
                        onStatusChanged()
Futureproof your sync
Futureproof your sync



  1. Be lenient on GET
Futureproof your sync



  1. Be lenient on GET
  2. Be strict on POST
Futureproof your sync



  1. Be lenient on GET
  2. Be strict on POST
  3. Have resync in v1.0
?
Thanks.

Mais conteúdo relacionado

Mais procurados

Deep Dive on Amazon Cognito - DevDay Austin 2017
Deep Dive on Amazon Cognito - DevDay Austin 2017Deep Dive on Amazon Cognito - DevDay Austin 2017
Deep Dive on Amazon Cognito - DevDay Austin 2017
Amazon Web Services
 

Mais procurados (20)

Azure AD B2C Webinar Series: Identity Protocols OIDC and OAuth2 part 1
Azure AD B2C Webinar Series: Identity Protocols OIDC and OAuth2 part 1Azure AD B2C Webinar Series: Identity Protocols OIDC and OAuth2 part 1
Azure AD B2C Webinar Series: Identity Protocols OIDC and OAuth2 part 1
 
(MBL401) Social Logins for Mobile Apps with Amazon Cognito | AWS re:Invent 2014
(MBL401) Social Logins for Mobile Apps with Amazon Cognito | AWS re:Invent 2014(MBL401) Social Logins for Mobile Apps with Amazon Cognito | AWS re:Invent 2014
(MBL401) Social Logins for Mobile Apps with Amazon Cognito | AWS re:Invent 2014
 
Microsoft Graph developer community call-March 2020
Microsoft Graph developer community call-March 2020Microsoft Graph developer community call-March 2020
Microsoft Graph developer community call-March 2020
 
Integrating an App with Amazon Web Services SimpleDB - A Matter of Choices
Integrating an App with Amazon Web Services SimpleDB - A Matter of ChoicesIntegrating an App with Amazon Web Services SimpleDB - A Matter of Choices
Integrating an App with Amazon Web Services SimpleDB - A Matter of Choices
 
Azure AD B2C Webinar Series: Custom Policies Part 1
Azure AD B2C Webinar Series: Custom Policies Part 1Azure AD B2C Webinar Series: Custom Policies Part 1
Azure AD B2C Webinar Series: Custom Policies Part 1
 
Deep Dive on Amazon Cognito - DevDay Austin 2017
Deep Dive on Amazon Cognito - DevDay Austin 2017Deep Dive on Amazon Cognito - DevDay Austin 2017
Deep Dive on Amazon Cognito - DevDay Austin 2017
 
Building Mobile Apps on AWS at Websummit Diublin
Building Mobile Apps on AWS at Websummit DiublinBuilding Mobile Apps on AWS at Websummit Diublin
Building Mobile Apps on AWS at Websummit Diublin
 
Managing Identity and Securing Your Mobile and Web Applications with Amazon C...
Managing Identity and Securing Your Mobile and Web Applications with Amazon C...Managing Identity and Securing Your Mobile and Web Applications with Amazon C...
Managing Identity and Securing Your Mobile and Web Applications with Amazon C...
 
Build Your Mobile App Faster with AWS Mobile Services
Build Your Mobile App Faster with AWS Mobile ServicesBuild Your Mobile App Faster with AWS Mobile Services
Build Your Mobile App Faster with AWS Mobile Services
 
Azure AD B2C Webinar Series: Custom Policies Part 3 Troubleshooting
Azure AD B2C Webinar Series: Custom Policies Part 3 TroubleshootingAzure AD B2C Webinar Series: Custom Policies Part 3 Troubleshooting
Azure AD B2C Webinar Series: Custom Policies Part 3 Troubleshooting
 
Deep Dive on User Sign-up Sign-in with Amazon Cognito - AWS Online Tech Talks
Deep Dive on User Sign-up Sign-in with Amazon Cognito - AWS Online Tech TalksDeep Dive on User Sign-up Sign-in with Amazon Cognito - AWS Online Tech Talks
Deep Dive on User Sign-up Sign-in with Amazon Cognito - AWS Online Tech Talks
 
Authentication and Identity with Amazon Cognito
Authentication and Identity with Amazon CognitoAuthentication and Identity with Amazon Cognito
Authentication and Identity with Amazon Cognito
 
Authentication & Authorization for Connected Mobile & Web Applications using ...
Authentication & Authorization for Connected Mobile & Web Applications using ...Authentication & Authorization for Connected Mobile & Web Applications using ...
Authentication & Authorization for Connected Mobile & Web Applications using ...
 
24032022 Zero Trust for Developers Pub.pdf
24032022 Zero Trust for Developers Pub.pdf24032022 Zero Trust for Developers Pub.pdf
24032022 Zero Trust for Developers Pub.pdf
 
Implement Authorization in your Apps with Microsoft identity platform-June 2020
Implement Authorization in your Apps with Microsoft identity platform-June 2020Implement Authorization in your Apps with Microsoft identity platform-June 2020
Implement Authorization in your Apps with Microsoft identity platform-June 2020
 
Office 365 api vs share point app model
Office 365 api vs share point app modelOffice 365 api vs share point app model
Office 365 api vs share point app model
 
Serverless Patterns: “No server is easier to manage than no server” - AWS Sec...
Serverless Patterns: “No server is easier to manage than no server” - AWS Sec...Serverless Patterns: “No server is easier to manage than no server” - AWS Sec...
Serverless Patterns: “No server is easier to manage than no server” - AWS Sec...
 
Amazon Cognito
Amazon CognitoAmazon Cognito
Amazon Cognito
 
Amazon Cognito Deep Dive
Amazon Cognito Deep DiveAmazon Cognito Deep Dive
Amazon Cognito Deep Dive
 
Cloud-powered Cross-platform Mobile Apps on AWS
Cloud-powered Cross-platform Mobile Apps on AWSCloud-powered Cross-platform Mobile Apps on AWS
Cloud-powered Cross-platform Mobile Apps on AWS
 

Semelhante a Sync on Android

Dev suite integration
Dev suite integrationDev suite integration
Dev suite integration
iemu
 

Semelhante a Sync on Android (20)

Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)
Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)
Build Your Mobile App Faster with AWS Mobile Services (Part 1 - AWS)
 
Build high performing mobile apps, faster with AWS
Build high performing mobile apps, faster with AWSBuild high performing mobile apps, faster with AWS
Build high performing mobile apps, faster with AWS
 
Build and Deploy Your Mobile Games
Build and Deploy Your Mobile Games Build and Deploy Your Mobile Games
Build and Deploy Your Mobile Games
 
What's new in the July 2017 Update for Dynamics 365 - Developer features
What's new in the July 2017 Update for Dynamics 365 - Developer featuresWhat's new in the July 2017 Update for Dynamics 365 - Developer features
What's new in the July 2017 Update for Dynamics 365 - Developer features
 
Lightweight Xtext Editors as SWT Widgets
Lightweight Xtext Editors as SWT WidgetsLightweight Xtext Editors as SWT Widgets
Lightweight Xtext Editors as SWT Widgets
 
Introduction to Microservices by Jim Tran, Principal Solutions Architect, AWS
Introduction to Microservices by Jim Tran, Principal Solutions Architect, AWSIntroduction to Microservices by Jim Tran, Principal Solutions Architect, AWS
Introduction to Microservices by Jim Tran, Principal Solutions Architect, AWS
 
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
MongoDB World 2018: Ch-Ch-Ch-Ch-Changes: Taking Your Stitch Application to th...
 
Faites évoluer votre accès aux données avec MongoDB Stitch
Faites évoluer votre accès aux données avec MongoDB StitchFaites évoluer votre accès aux données avec MongoDB Stitch
Faites évoluer votre accès aux données avec MongoDB Stitch
 
Connect + Docker + AWS = Bitbucket Pipelines
Connect + Docker + AWS = Bitbucket PipelinesConnect + Docker + AWS = Bitbucket Pipelines
Connect + Docker + AWS = Bitbucket Pipelines
 
ASP.NET Lecture 6
ASP.NET Lecture 6ASP.NET Lecture 6
ASP.NET Lecture 6
 
Dev suite integration
Dev suite integrationDev suite integration
Dev suite integration
 
(MBL302) Mastering Synchronization Across Mobile Devices, Login Providers, an...
(MBL302) Mastering Synchronization Across Mobile Devices, Login Providers, an...(MBL302) Mastering Synchronization Across Mobile Devices, Login Providers, an...
(MBL302) Mastering Synchronization Across Mobile Devices, Login Providers, an...
 
Introduction to Microservices
Introduction to MicroservicesIntroduction to Microservices
Introduction to Microservices
 
Itb 2021 - Bulding Quick APIs by Gavin Pickin
Itb 2021 - Bulding Quick APIs by Gavin PickinItb 2021 - Bulding Quick APIs by Gavin Pickin
Itb 2021 - Bulding Quick APIs by Gavin Pickin
 
BlackBerry10 apps with Adobe AIR & Apache Flex - BlackBerry JAM Europe
BlackBerry10 apps with Adobe AIR & Apache Flex - BlackBerry JAM EuropeBlackBerry10 apps with Adobe AIR & Apache Flex - BlackBerry JAM Europe
BlackBerry10 apps with Adobe AIR & Apache Flex - BlackBerry JAM Europe
 
Build Your Mobile App Faster with AWS Mobile Services
Build Your Mobile App Faster with AWS Mobile ServicesBuild Your Mobile App Faster with AWS Mobile Services
Build Your Mobile App Faster with AWS Mobile Services
 
Deep Dive into SpaceONE
Deep Dive into SpaceONEDeep Dive into SpaceONE
Deep Dive into SpaceONE
 
Pycon Korea 2018-Sanic을 활용하여 Microservice 구축하기-이재면
Pycon Korea 2018-Sanic을 활용하여 Microservice 구축하기-이재면Pycon Korea 2018-Sanic을 활용하여 Microservice 구축하기-이재면
Pycon Korea 2018-Sanic을 활용하여 Microservice 구축하기-이재면
 
App Modernization with Microsoft Azure
App Modernization with Microsoft AzureApp Modernization with Microsoft Azure
App Modernization with Microsoft Azure
 
Exam 70-488 Developing Microsoft SharePoint Server 2013 Core Solutions Learni...
Exam 70-488 Developing Microsoft SharePoint Server 2013 Core Solutions Learni...Exam 70-488 Developing Microsoft SharePoint Server 2013 Core Solutions Learni...
Exam 70-488 Developing Microsoft SharePoint Server 2013 Core Solutions Learni...
 

Último

Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Victor Rentea
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
Modular Monolith - a Practical Alternative to Microservices @ Devoxx UK 2024
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Exploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with MilvusExploring Multimodal Embeddings with Milvus
Exploring Multimodal Embeddings with Milvus
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
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
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
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...
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
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
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
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...
 

Sync on Android

  • 1. Sync ON ANDROID Jerzy Chalupski chalup jerzy@futuresimple.com
  • 2. What we do in general...
  • 3. What we do ALL THE TIME sync, sync, sync, sync
  • 4. Sync ON ANDROID OVERVIEW ARCHITECTURE CONTENT PROVIDER PITFALLS & PROTIPS
  • 5. Sync ON ANDROID OVERVIEW ARCHITECTURE CONTENT PROVIDER PITFALLS & PROTIPS
  • 6. Not exactly the fresh topic... „Developing Android REST client applications” by Virgil Dobjanschi @Google I/O 2010
  • 7. Not exactly the fresh topic... „Synchronizacja danych z serwisami webowymi w Androidzie” by Bartosz Filipowicz @KrakDroid 2011
  • 8. Not exactly the fresh topic... „Synchronizacja danych z serwisami webowymi w Androidzie” by Bartosz Filipowicz @KrakDroid 2011 ...but there is still much confusion
  • 9. AccountManager SyncManager UI Authenticator ContentProvider SyncAdapter ContentResolver
  • 10. „Wat? Why do I need to write all this crap, sync is just fetching data from server” typical reaction
  • 12. Sync provides data sharing offline mode
  • 13. Sync provides data sharing offline mode responsive UI
  • 14. Sync provides data sharing offline mode responsive UI GREAT UX
  • 15. Sync ON ANDROID OVERVIEW ARCHITECTURE CONTENT PROVIDER PITFALLS & PROTIPS
  • 16. ContentProvider 101: CRUD CREATE insert() READ query() UPDATE update() DELETE delete()
  • 17. ContentProvider 101: URI content://com.futuresimple.krakdroid.Provider/datasets/1
  • 18. ContentProvider 101: URI content://com.futuresimple.krakdroid.Provider/datasets/1
  • 19. ContentProvider 101: URI content://com.futuresimple.krakdroid.Provider/datasets/1
  • 20. ContentProvider 101: URI content://com.futuresimple.krakdroid.Provider/datasets/1
  • 21. ContentProvider 101: notifications content://com.futuresimple.krakdroid.Provider/datasets/1 content://com.futuresimple.krakdroid.Provider/solutions content://com.futuresimple.krakdroid.Provider/solutions/1 content://com.futuresimple.krakdroid.Provider/solutions/1/answers/1 content://com.futuresimple.krakdroid.Provider/solutions/1/answers/2 content://com.futuresimple.krakdroid.Provider/solutions/2/answers/1
  • 22. ContentProvider 101: notifications content://com.futuresimple.krakdroid.Provider/datasets/1 content://com.futuresimple.krakdroid.Provider/solutions content://com.futuresimple.krakdroid.Provider/solutions/1 content://com.futuresimple.krakdroid.Provider/solutions/1/answers/1 content://com.futuresimple.krakdroid.Provider/solutions/1/answers/2 content://com.futuresimple.krakdroid.Provider/solutions/2/answers/1 ContentResolver.notifyChange(“content:// com.futuresimple.krakdroid.Provider/datasets/1”);
  • 23. ContentProvider 101: notifications content://com.futuresimple.krakdroid.Provider/datasets/1 content://com.futuresimple.krakdroid.Provider/solutions content://com.futuresimple.krakdroid.Provider/solutions/1 content://com.futuresimple.krakdroid.Provider/solutions/1/answers/1 content://com.futuresimple.krakdroid.Provider/solutions/1/answers/2 content://com.futuresimple.krakdroid.Provider/solutions/2/answers/1 ContentResolver.notifyChange(“content:// com.futuresimple.krakdroid.Provider/solutions/1/answers/1”);
  • 24. Sync ON ANDROID OVERVIEW ARCHITECTURE CONTENT PROVIDER PITFALLS & PROTIPS
  • 25. AccountManager SyncManager UI Authenticator ContentProvider SyncAdapter ContentResolver
  • 26. Authenticator Sync architecture CREATING NEW ACCOUNT AccountManager addAccount() UI SyncManager ContentResolver SyncAdapter ContentProvider
  • 27. Authenticator Sync architecture CREATING NEW ACCOUNT addAccount() AccountManager addAccount() UI SyncManager ContentResolver SyncAdapter ContentProvider
  • 28. Authenticator Sync architecture CREATING NEW ACCOUNT addAccount() AccountManager addAccount() UI SyncManager ContentResolver SyncAdapter ContentProvider
  • 29. Authenticator Sync architecture SHOW SYNCED DATA AccountManager UI query() SyncManager ContentResolver query() SyncAdapter ContentProvider
  • 30. Authenticator Sync architecture REQUEST SYNC AccountManager getAccountsByType() UI SyncManager ContentResolver SyncAdapter ContentProvider
  • 31. Authenticator Sync architecture REQUEST SYNC AccountManager getAccountsByType() UI requestSync() SyncManager ContentResolver SyncAdapter ContentProvider
  • 32. Authenticator Sync architecture REQUEST SYNC AccountManager getAccountsByType() UI requestSync() SyncManager ContentResolver onPerformSync() SyncAdapter ContentProvider
  • 33. Authenticator Sync architecture EDIT DATA AccountManager UI insert() SyncManager ContentResolver insert() SyncAdapter ContentProvider
  • 34. Authenticator Sync architecture EDIT DATA AccountManager UI insert() SyncManager ContentResolver notifyChange() insert() SyncAdapter ContentProvider
  • 35. Authenticator Sync architecture EDIT DATA AccountManager UI insert() SyncManager ContentResolver notifyChange() insert() SyncAdapter ContentProvider
  • 36. Authenticator Sync architecture EDIT DATA AccountManager getAccountsByType() UI insert() SyncManager ContentResolver notifyChange() insert() SyncAdapter ContentProvider
  • 37. Authenticator Sync architecture EDIT DATA AccountManager getAccountsByType() UI insert() SyncManager ContentResolver onPerformSync() notifyChange() insert() SyncAdapter ContentProvider
  • 38. Authenticator Sync architecture POST NEW DATA AccountManager UI SyncManager ContentResolver onPerformSync() SyncAdapter ContentProvider
  • 39. Authenticator Sync architecture POST NEW DATA getAuthToken() AccountManager UI SyncManager ContentResolver onPerformSync() SyncAdapter ContentProvider
  • 40. Authenticator Sync architecture POST NEW DATA getAuthToken() AccountManager UI SyncManager ContentResolver query() onPerformSync() query() SyncAdapter ContentProvider
  • 41. Authenticator Sync architecture POST NEW DATA getAuthToken() AccountManager UI SyncManager ContentResolver query() onPerformSync() query() SyncAdapter POST ContentProvider
  • 42. Authenticator Sync architecture GET NEW DATA AccountManager UI SyncManager ContentResolver onPerformSync() SyncAdapter ContentProvider
  • 43. Authenticator Sync architecture GET NEW DATA getAuthToken() AccountManager UI SyncManager ContentResolver onPerformSync() SyncAdapter ContentProvider
  • 44. Authenticator Sync architecture GET NEW DATA getAuthToken() AccountManager UI SyncManager ContentResolver onPerformSync() SyncAdapter GET ContentProvider
  • 45. Authenticator Sync architecture GET NEW DATA getAuthToken() AccountManager UI SyncManager ContentResolver applyBatch() onPerformSync() applyBatch() SyncAdapter GET ContentProvider
  • 46. Authenticator Sync architecture GET NEW DATA getAuthToken() AccountManager UI SyncManager ContentResolver applyBatch() onPerformSync() notifyChange() applyBatch() SyncAdapter GET ContentProvider
  • 47. Authenticator Sync architecture GET NEW DATA getAuthToken() AccountManager onLoaderFinished() UI SyncManager ContentResolver applyBatch() onPerformSync() notifyChange() applyBatch() SyncAdapter GET ContentProvider
  • 48. Authenticator Sync architecture WIN #1: NO REMOTE I/O IN UI AccountManager UI SyncManager ContentResolver SyncAdapter ContentProvider
  • 49. Authenticator Sync architecture WIN #2: SYNC SCHEDULING AccountManager UI SyncManager ContentResolver SyncAdapter ContentProvider
  • 50. Sync ON ANDROID OVERVIEW ARCHITECTURE CONTENT PROVIDER PITFALLS & PROTIPS
  • 51. IDs in ContentProvider URIs content://com.futuresimple.krakdroid.Provider/datasets/1
  • 52. IDs in ContentProvider URIs content://com.futuresimple.krakdroid.Provider/datasets/1 Plan A: Use local IDs! (BaseColumns._ID)
  • 53. IDs in ContentProvider URIs content://com.futuresimple.krakdroid.Provider/datasets/1 Plan A: Use local IDs! (BaseColumns._ID) ISSUE: still need server-side IDs for relations
  • 54. IDs in ContentProvider URIs content://com.futuresimple.krakdroid.Provider/datasets/1 Plan A: Use local IDs! (BaseColumns._ID) ISSUE: still need server-side IDs for relations ISSUE: conversions between server and local IDs
  • 55. IDs in ContentProvider URIs content://com.futuresimple.krakdroid.Provider/datasets/15002900 Plan B: OK, use server-side IDs!
  • 56. IDs in ContentProvider URIs content://com.futuresimple.krakdroid.Provider/datasets/15002900 Plan B: OK, use server-side IDs! ISSUE: what about offline mode?
  • 57. IDs in ContentProvider URIs content://com.futuresimple.krakdroid.Provider/datasets/-42 content://com.futuresimple.krakdroid.Provider/datasets/15002900 Plan C: OK, let’s mix things up!
  • 58. IDs in ContentProvider URIs content://com.futuresimple.krakdroid.Provider/datasets/-42 content://com.futuresimple.krakdroid.Provider/datasets/15002900 Plan C: OK, let’s mix things up! ISSUE: very tricky implementation
  • 59. IDs in ContentProvider URIs content://com.futuresimple.krakdroid.Provider/datasets/GUID Plan D: GUID
  • 60. IDs in ContentProvider URIs content://com.futuresimple.krakdroid.Provider/datasets/GUID Plan D: GUID ISSUE: needs support on the backend
  • 61. ContentResolver requestSync() vs. notifyChange() requestSync(account, authority, extras) notifyChange(uri, observer, syncToNetwork)
  • 62. ContentResolver requestSync() vs. notifyChange() requestSync(account, authority, extras) notifyChange(uri, observer, syncToNetwork)
  • 63. Deleting an account From your app From system settings From 3rd party app
  • 64. Deleting an account From your app “Where should I From system settings perform user data cleanup?” From 3rd party app
  • 65. Deleting an account @Override getAccountRemovalAllowed()
  • 66. Deleting an account @Override getAccountRemovalAllowed() CONS: depends on current Settings implementation. PROS: exactly the thing you need.
  • 67. Deleting an account <receiver android:name=".auth.AccountBroadcastReceiver" android:enabled="true" > <intent-filter> <action android:name="android.accounts.LOGIN_ACCOUNTS_CHANGED" /> </intent-filter> </receiver>
  • 68. Deleting an account <receiver android:name=".auth.AccountBroadcastReceiver" android:enabled="true" > <intent-filter> <action android:name="android.accounts.LOGIN_ACCOUNTS_CHANGED" /> </intent-filter> </receiver> CONS: only info about existing accounts. PROS: peace of mind.
  • 69. Sync lifecycle Happy case:
  • 70. Sync lifecycle Happy case: requestSync()
  • 71. Sync lifecycle Happy case: onPerformSync() requestSync()
  • 72. Sync lifecycle Happy case: onPerformSync() requestSync() onStatusChanged()
  • 73. Sync lifecycle Not-so-happy case: onPerformSync() requestSync() onStatusChanged()
  • 74. Sync lifecycle Not-so-happy case: onPerformSync() requestSync() onStatusChanged()
  • 75. Sync lifecycle Not-so-happy case: onPerformSync() requestSync() cancelSync() + onStatusChanged()
  • 77. Futureproof your sync 1. Be lenient on GET
  • 78. Futureproof your sync 1. Be lenient on GET 2. Be strict on POST
  • 79. Futureproof your sync 1. Be lenient on GET 2. Be strict on POST 3. Have resync in v1.0
  • 80. ?
  • 81.
  • 82.