SlideShare a Scribd company logo
A PRIMER TO
SYNC ADAPTERS
    Kiana Tennyson
        mdevcon
   Tuschinski Theater
     March 2013
OVERVIEW

v Who is Kiana?
v SyncAdapter Use Cases
v The Big Picture
v Configuration
v Authorization, Content, Synchronization
v Wrap up/Questions
WHO’S KIANA?

v Software Developer

v Professional background working on web portals

v Work at Manheim, wholesale vehicle auction company

v Customer facing applications
     •  Web portal (www.manheim.com) Ruby, Java, JS
     •  iOS app
     •  Android app
SYNC ADAPTERS ARE…?

v Share data between a remote data source and an Android
device

v Android OS provides plug-in architecture that takes care of:
     •    Coordinating network availability with syncing all datasources
     •    Scheduling synchronization/Handling stopped processes
     •    Accommodating user preferences when syncing
     •     Handling network interruptions
TOUGH PARTS

v Good news! Writing a Custom SyncAdapter is actually easy!

v Bad news. There are potentially tough parts:
     •  Authentication Handling
     •  (Custom) Content Provider
     •  Data Handling

v Defined by business rules
BEST USE CASES

Application that…

v Requires authentication step to connect to remote
datasource

v Potentially could use a built-in ContentProvider
     •  All providers found in android.provider package

v Application Suite backed by custom ContentProvider
!(BEST USE CASES)

v Anything that DOES NOT require a login
v Any source that provides an RSS feed
     •  Typically public data sources like news/media sites
     •  Write a parser that reads the feed only when the user wants it
     •  SyncAdapter not necessary to write to the ContentProvider

v If Service does not constantly need to run in the
background
     •  User has limited battery power, code with this in mind
A Primer to SyncAdapters


CONFIGURATION
THE BIG PICTURE

AccountManager           SyncManager                  ContentProvider

    •  Requires              •  Uses Account              •  Holds the data
       Authentication           List as a basis for       •  Called in
       Service to add           it’s Sync List              onPerformSync()
       Account               •  Requires Sync
    •  Adds Account to          Service to start
       Account List             data syncs
AUTHENTICATION

v Write an AuthActivity
    •  serves UI for user to enter account info
    •  Write it to complete the authorization process

v Write an Authenticator
    •  MUST extend AbstractAccountAuthenticator
    •  Returns the AuthActivity in a Bundle object

v Write an Authentication Service
    •  MUST extend Service
    •  onBind return IBinder for the Authenticator
SYNCHRONIZATION

v Write a SyncAdapter
    •  MUST extend AbstractThreadedSyncAdapter
    •  Overwrite onPerformSync()

v Write a Sync Service
    •  MUST extend Service
    •  Allow creation of ONE SyncAdapter
    •  onBind returns a IBinder for SyncAdapter
RESOURCE XMLS

v Provide configuration info

v Map account type to objects
     •  SyncAdapter and Authenticator are connected via
        android:accountType

v Map content authority to SyncAdapter
RESOURCE XMLS

<?xml version="1.0" encoding="utf-8"?>!
<account-authenticator xmlns:android="http://
      !schemas.android.com/apk/res/android”!

  android:accountType=”your.uniquename.here"!

  android:icon="@drawable/icon"!

  android:smallIcon="@drawable/icon"!

  android:label="@string/label"!

/>!
Add Account
v  Notice result of android:icon

v  Green lights – Account added

v  Gray lights – Account not added

v  Clicking one launches Auth
   Activity interface
RESOURCE XMLS

<?xml version="1.0" encoding="utf-8"?>!
<sync-adapter xmlns:android="http://
      !schemas.android.com/apk/res/android”!

  android:contentAuthority="com.android.contacts"!

  android:accountType="your.uniquename.here"!

  android:supportsUploading="false"!

  android:userVisible="true"!

/>!
MANIFEST
v Several appropriate permissions

v Declare AuthenticationService with <service> tag
     •  Intent filter: “android.accounts.AccountAuthenticator”
     •  Meta-data tag points AccountAuthenticator to xml resource file

v Declare SyncService with <service> tag
     •  Intent filter: “android.content.SyncAdapter”
     •  Meta-data tag points SyncAdapter to xml resource file
     •  Other Meta-data tag defines custom MIME-types

v Declare AuthActivity (no Intent filter necessary)
MANIFEST.XML
<service android:name=".authenticator.AuthenticationService”
         !android:exported="true”>!
    <intent-filter>!
        <action android:name="android.accounts.AccountAuthenticator" />!
    </intent-filter>!
    <meta-data android:name="android.accounts.AccountAuthenticator”!
         !android:resource="@xml/authenticator" />!
</service>!
<service android:name=".syncadapter.SyncService” android:exported="true">!
    <intent-filter>!
        <action android:name="android.content.SyncAdapter" />!
    </intent-filter>!
    <meta-data android:name="android.content.SyncAdapter”!
         !android:resource="@xml/syncadapter" />!
    <meta-data android:name="android.provider.CONTACTS_STRUCTURE”!
         !android:resource="@xml/contacts" />!
</service>!
WHY SERVICES?

v SyncAdapter is bound to a service, Authentication is bound to a
service… but why?

v SyncManager finds all syncAdapters via a SyncAdaptersCache.

v AccountManager finds all Accounts via AccountAuthenticatorCache

v RegisteredServicesCache
     •  Reads the XML files created (account-authenticator and syncadapter)
     •  Generates service maps
CODE SUMMARY

v Create a syncadapter.xml file
v Create an authenticator.xml file
v Add an authentication <service> to manifest
v Add a sync <service> to manifest
v Add correct permissions to manifest
v Write some java… but what does any of this mean?
A Primer to SyncAdapters


THE DATA
ACCESSING CONTENT
                                                      •  SharedPreferences
                                  Data Storage        •  External Storage
                                                      •  SQLLiteDatabase

                                ContentProvider

                              ContentProviderClient

                            ContentResolver

                        Context

                  Android Application(s)
The Device User
CONTENT PROVIDER

v Manages central repository of data.

v SyncAdapters wouldn’t exist without ContentProviders
     •  SyncAdapter mentioned in ContentProvider section of API
        Guide

v Built in ContentProviders contain a SyncState table
     •  Use to store sync state, meta-data or any sync related data

v Sync related columns in other tables:
     •  DIRTY, VERSION, SOURCE_ID
IMPORTANT COLUMNS
v DIRTY (local modifications)
    •  Indicates data row has been changed locally since last sync.
    •  When SyncAdapter adds/updates a row, append
       “CALLER_IS_SYNCADAPTER” to Content URI
v VERSION
    •  Incremented by Provider whenever the data row is changed.
    •  High-water marking (aka lastSyncState)

v SOURCE_ID
    •  Unique ID for data row (primary key on the remote datasource)
    •  If set to null, indicates to SyncAdapter to create new row on remote
       source
CUSTOM
       CONTENT PROVIDER

v What properties make the built-in ContentProviders
“syncable”?
    •  Extra “For Sync use only” table that holds metadata
    •  “CALLER_IS_SYNCADAPTER” query param
    •  Use of “high-water-mark” is essential

v These properties should be applied to Custom SyncAdapter
CONTENT RESOLVER VS
  CONTENTPROVIDER CLIENT
   ContentResolver                        ContentProviderClient
v  Thread safe                        v  Not thread safe

v  Many calls to many                 v  Repeated calls to same CA
          ContentAuthorities (CA)      v  Cheaper call (one CA lookup)
v  Expensive call (Many CA lookups)   v  You MUST call release() to avoid
v  Resolver contains a Client         memory leak
CONTENTPROVIDER
            CLIENT

v Part of onPerformSync() method signature.

v Not thread safe, so be careful with usage
     •  Utilize locking strategies, ensure no outside services are
        performing activities on sync-candidate data

v Android Sample project uses threadsafe ContentResolver
via a Manager
CONTENT RESOLVER

v Do I really need this? Your choice.
     •  ContentResolvers query the ContentProvider
     •  Use it to CRUD data inside syncAdapter.onPerformSync();
     •  SampleSyncAdapter uses the ContentResolver by way of it’s
        ContactsManager class, because it performs batch operations

v Retrieve it using: context.getContentResolver();

v However, there are other ways to access the data
DATA CONSIDERATIONS

v Determine structure of serialized/transmitted data
     •  Using json? xml? yaml?
     •  What does a single row (data unit) look like?

v How does the server parse and save the transmitted data?
     •  Likely defined by business limitations.

v How does the device parse/save the data?
     •  ContentProviderClient or ContentResolver (batch ops)
A Primer to SyncAdapters


AUTHENTICATION
ACCOUNT

v Account object contains an Account name and Account type.
    •  Note, the Account object does NOT contain a password
    •  Example: user has multiple twitter accounts

v AccountManager maps an Account object to it’s “password”

v Recommended strategy: store Account and authToken on device
    •  SampleSyncAdapter project stores password (possible human error)

v SyncManager can only schedule syncs per Account
ACCOUNT MANAGER

v Contains centralized registry of user’s online accounts

v Used to determine list of data sources to be synced
     •  AccountManager provides list of Accounts
     •  SyncManager grabs the list of Accounts for syncing

v AccountAuthenticatorCache maps accountType to objects
extending AbstractAccountAuthenticator

v Android Component; you don’t write this
AUTHENTICATION

v User chooses to Add an Account
     •  List compiled from array of allowable account types

v System chooses Authenticator based on
“android:accountType”
     •  Binds to a Service which returns the Authenticator’s IBinder

v Authenticator’s overridden addAccount() method is called
     •  Ultimately the Login UI displays, new Account is created
AUTHENTICATOR

v Allows developer to implement authentication
     •  Per remote service

v Must extend AbstractAccountAuthenticator
     •  Responds to an intent “android.accounts.AccountAuthenticator”
        advertised by the AccountManager for it’s accountType only.

v Authentication Service returns a Binder to your implemented
AbstractAccountAuthenticator

v addAccount() returns bundle with intent containing Activity
ADD ACCOUNT
Sample SyncAdapter Activity   Example Activity
A Primer to SyncAdapters


THE SYNC
SYNCMANAGER

v Responsible for scheduling, cancelling syncs.
     •  Maintains a list of active syncs (mActiveSyncContext)

v Sync handling strategy very tightly coupled to Accounts
     •  Account is part of most SyncManager methods

v How do the SyncHandler and Account interact?
     •  SyncHandler receives a message containing an
        ActiveSyncContext. ActiveSyncContext contains all
        information about the sync that needs to begin including the
        Account.
SYNCHRONIZATION

v SyncManager contains ONE SyncHandler

v SyncHandler’s job: receive/handle sync operation messages
    •  On receiving a Connection Message, calls startSync for the
       syncAdapter in question
    •  startSync() spins up a new SyncThread
    •  The method onPerformSync() that was implemented is
       invoked when run() is invoked on the thread
SYNC ADAPTER

v Where the main party happens. The method onPerformSync()
gets called within a syncThread.run()

v Make use of the DIRTY/VERSION/SOURCE_ID rows

v Instantiate like any class.
     •  However, create only one for thread safety.
ONPERFORMSYNC()

v What should I do in the onPerformSync() method?

v Merge remote data with local data
       •  DIRTY/VERSION/SOURCE_ID columns

v Use business rules to determine order of operations
       •  Whether local data overwrites remote data or vice versa

v Implement a remote connection strategy to access remote
data
DEV TOOLS
WRAP UP

v We learned…
    •    What SyncAdapters are
    •    Set up
    •    Content (ContentProvider/data characteristics)
    •    Authorization (Accounts, Account Management)
    •    Synchronization (SyncManager, SyncService)
    •    Debugging/Dev Tools
A Primer to SyncAdapters


QUESTIONS?

More Related Content

What's hot

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)
Amazon Web Services
 
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
Amazon Web Services
 
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
Shiva Narayanaswamy
 
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
Mark Maslyn
 
Community call: Develop multi tenant apps with the Microsoft identity platform
Community call: Develop multi tenant apps with the Microsoft identity platformCommunity call: Develop multi tenant apps with the Microsoft identity platform
Community call: Develop multi tenant apps with the Microsoft identity platform
Microsoft 365 Developer
 
Asp.net html server control
Asp.net html  server controlAsp.net html  server control
Asp.net html server control
Sireesh K
 
ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828Viral Patel
 
(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
Amazon Web Services
 
Build Your Mobile App Faster with AWS Mobile Services (Cognito, Lambda, SNS, ...
Build Your Mobile App Faster with AWS Mobile Services (Cognito, Lambda, SNS, ...Build Your Mobile App Faster with AWS Mobile Services (Cognito, Lambda, SNS, ...
Build Your Mobile App Faster with AWS Mobile Services (Cognito, Lambda, SNS, ...
Amazon Web Services
 
(MBL311) Workshop: Build an Android App Using AWS Mobile Services | AWS re:In...
(MBL311) Workshop: Build an Android App Using AWS Mobile Services | AWS re:In...(MBL311) Workshop: Build an Android App Using AWS Mobile Services | AWS re:In...
(MBL311) Workshop: Build an Android App Using AWS Mobile Services | AWS re:In...
Amazon Web Services
 
Build a mobile app serverless with AWS Lambda
Build a mobile app serverless with AWS LambdaBuild a mobile app serverless with AWS Lambda
Build a mobile app serverless with AWS Lambda
TheFamily
 
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
Amazon Web Services
 
Getting Started with your User Pools in Amazon Cognito - AWS June 2016 Webina...
Getting Started with your User Pools in Amazon Cognito - AWS June 2016 Webina...Getting Started with your User Pools in Amazon Cognito - AWS June 2016 Webina...
Getting Started with your User Pools in Amazon Cognito - AWS June 2016 Webina...
Amazon Web Services
 
(GAM401) Build a Serverless Mobile Game w/ Cognito, Lambda & DynamoDB
(GAM401) Build a Serverless Mobile Game w/ Cognito, Lambda & DynamoDB(GAM401) Build a Serverless Mobile Game w/ Cognito, Lambda & DynamoDB
(GAM401) Build a Serverless Mobile Game w/ Cognito, Lambda & DynamoDB
Amazon Web Services
 
Mobile App Development with Amazon Web Services Mobile Hub
Mobile App Development with Amazon Web Services Mobile HubMobile App Development with Amazon Web Services Mobile Hub
Mobile App Development with Amazon Web Services Mobile Hub
Amazon Web Services
 
Using Windows Azure for Solving Identity Management Challenges (Visual Studio...
Using Windows Azure for Solving Identity Management Challenges (Visual Studio...Using Windows Azure for Solving Identity Management Challenges (Visual Studio...
Using Windows Azure for Solving Identity Management Challenges (Visual Studio...
Michael Collier
 
Microsoft identity platform community call-May 2020
Microsoft identity platform community call-May 2020Microsoft identity platform community call-May 2020
Microsoft identity platform community call-May 2020
Microsoft 365 Developer
 
AWS September Webinar Series - Build Cross-Platform Mobile Apps with AWS and...
AWS September Webinar Series -  Build Cross-Platform Mobile Apps with AWS and...AWS September Webinar Series -  Build Cross-Platform Mobile Apps with AWS and...
AWS September Webinar Series - Build Cross-Platform Mobile Apps with AWS and...
Amazon Web Services
 

What's hot (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 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
 
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
 
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
 
Asp.net controls
Asp.net controlsAsp.net controls
Asp.net controls
 
Community call: Develop multi tenant apps with the Microsoft identity platform
Community call: Develop multi tenant apps with the Microsoft identity platformCommunity call: Develop multi tenant apps with the Microsoft identity platform
Community call: Develop multi tenant apps with the Microsoft identity platform
 
Asp.net html server control
Asp.net html  server controlAsp.net html  server control
Asp.net html server control
 
ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828ASP.NET User Controls - 20090828
ASP.NET User Controls - 20090828
 
(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
 
Build Your Mobile App Faster with AWS Mobile Services (Cognito, Lambda, SNS, ...
Build Your Mobile App Faster with AWS Mobile Services (Cognito, Lambda, SNS, ...Build Your Mobile App Faster with AWS Mobile Services (Cognito, Lambda, SNS, ...
Build Your Mobile App Faster with AWS Mobile Services (Cognito, Lambda, SNS, ...
 
(MBL311) Workshop: Build an Android App Using AWS Mobile Services | AWS re:In...
(MBL311) Workshop: Build an Android App Using AWS Mobile Services | AWS re:In...(MBL311) Workshop: Build an Android App Using AWS Mobile Services | AWS re:In...
(MBL311) Workshop: Build an Android App Using AWS Mobile Services | AWS re:In...
 
Build a mobile app serverless with AWS Lambda
Build a mobile app serverless with AWS LambdaBuild a mobile app serverless with AWS Lambda
Build a mobile app serverless with AWS Lambda
 
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
 
Getting Started with your User Pools in Amazon Cognito - AWS June 2016 Webina...
Getting Started with your User Pools in Amazon Cognito - AWS June 2016 Webina...Getting Started with your User Pools in Amazon Cognito - AWS June 2016 Webina...
Getting Started with your User Pools in Amazon Cognito - AWS June 2016 Webina...
 
Standard control in asp.net
Standard control in asp.netStandard control in asp.net
Standard control in asp.net
 
(GAM401) Build a Serverless Mobile Game w/ Cognito, Lambda & DynamoDB
(GAM401) Build a Serverless Mobile Game w/ Cognito, Lambda & DynamoDB(GAM401) Build a Serverless Mobile Game w/ Cognito, Lambda & DynamoDB
(GAM401) Build a Serverless Mobile Game w/ Cognito, Lambda & DynamoDB
 
Mobile App Development with Amazon Web Services Mobile Hub
Mobile App Development with Amazon Web Services Mobile HubMobile App Development with Amazon Web Services Mobile Hub
Mobile App Development with Amazon Web Services Mobile Hub
 
Using Windows Azure for Solving Identity Management Challenges (Visual Studio...
Using Windows Azure for Solving Identity Management Challenges (Visual Studio...Using Windows Azure for Solving Identity Management Challenges (Visual Studio...
Using Windows Azure for Solving Identity Management Challenges (Visual Studio...
 
Microsoft identity platform community call-May 2020
Microsoft identity platform community call-May 2020Microsoft identity platform community call-May 2020
Microsoft identity platform community call-May 2020
 
AWS September Webinar Series - Build Cross-Platform Mobile Apps with AWS and...
AWS September Webinar Series -  Build Cross-Platform Mobile Apps with AWS and...AWS September Webinar Series -  Build Cross-Platform Mobile Apps with AWS and...
AWS September Webinar Series - Build Cross-Platform Mobile Apps with AWS and...
 

Similar to mdevcon - A Primer to SyncAdapters

Fire up your mobile app!
Fire up your mobile app!Fire up your mobile app!
Fire up your mobile app!
Suganthi Giridharan
 
Build a Website on AWS for Your First 10 Million Users
Build a Website on AWS for Your First 10 Million UsersBuild a Website on AWS for Your First 10 Million Users
Build a Website on AWS for Your First 10 Million Users
Amazon Web Services
 
MongoDB.local Berlin: App development in a Serverless World
MongoDB.local Berlin: App development in a Serverless WorldMongoDB.local Berlin: App development in a Serverless World
MongoDB.local Berlin: App development in a Serverless World
MongoDB
 
O365Con18 - Hybrid SharePoint Deep Dive - Thomas Vochten
O365Con18 - Hybrid SharePoint Deep Dive - Thomas VochtenO365Con18 - Hybrid SharePoint Deep Dive - Thomas Vochten
O365Con18 - Hybrid SharePoint Deep Dive - Thomas Vochten
NCCOMMS
 
R.A.P. (Rely on Android Platform)
R.A.P. (Rely on Android Platform)R.A.P. (Rely on Android Platform)
R.A.P. (Rely on Android Platform)
Aditium
 
Windows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside worldWindows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside world
Prabhakaran Soundarapandian
 
Running Hybrid Cloud Patterns on AWS
Running Hybrid Cloud Patterns on AWSRunning Hybrid Cloud Patterns on AWS
Running Hybrid Cloud Patterns on AWS
Shiva Narayanaswamy
 
Accelerate your Cloud Success with Platform Services
Accelerate your Cloud Success with Platform ServicesAccelerate your Cloud Success with Platform Services
Accelerate your Cloud Success with Platform Services
Amazon Web Services
 
Introducing “Well-Architected” For Developers - Technical 101
Introducing “Well-Architected” For Developers - Technical 101Introducing “Well-Architected” For Developers - Technical 101
Introducing “Well-Architected” For Developers - Technical 101
Amazon Web Services
 
SRV418 Deep Dive on Accelerating Content, APIs, and Applications with Amazon ...
SRV418 Deep Dive on Accelerating Content, APIs, and Applications with Amazon ...SRV418 Deep Dive on Accelerating Content, APIs, and Applications with Amazon ...
SRV418 Deep Dive on Accelerating Content, APIs, and Applications with Amazon ...
Amazon Web Services
 
JUDCon 2014: Gearing up for mobile development with AeroGear
JUDCon 2014: Gearing up for mobile development with AeroGearJUDCon 2014: Gearing up for mobile development with AeroGear
JUDCon 2014: Gearing up for mobile development with AeroGear
prajods
 
Bridging the Gap Between Real Time/Offline and AI/ML Capabilities in Modern S...
Bridging the Gap Between Real Time/Offline and AI/ML Capabilities in Modern S...Bridging the Gap Between Real Time/Offline and AI/ML Capabilities in Modern S...
Bridging the Gap Between Real Time/Offline and AI/ML Capabilities in Modern S...
Amazon Web Services
 
Code first in the cloud: going serverless with Azure
Code first in the cloud: going serverless with AzureCode first in the cloud: going serverless with Azure
Code first in the cloud: going serverless with Azure
Jeremy Likness
 
Developing a provider hosted share point app
Developing a provider hosted share point appDeveloping a provider hosted share point app
Developing a provider hosted share point app
Talbott Crowell
 
Spring Social - Messaging Friends & Influencing People
Spring Social - Messaging Friends & Influencing PeopleSpring Social - Messaging Friends & Influencing People
Spring Social - Messaging Friends & Influencing People
Gordon Dickens
 
Build a Website on AWS for Your First 10 Million Users
Build a Website on AWS for Your First 10 Million UsersBuild a Website on AWS for Your First 10 Million Users
Build a Website on AWS for Your First 10 Million Users
Amazon Web Services
 
Building SPA’s (Single Page App) with Backbone.js
Building SPA’s (Single Page App) with Backbone.jsBuilding SPA’s (Single Page App) with Backbone.js
Building SPA’s (Single Page App) with Backbone.js
Microsoft Developer Network (MSDN) - Belgium and Luxembourg
 
Sviluppare Applicazioni Real Time con AppSync Deck.pptx
Sviluppare Applicazioni Real Time con AppSync Deck.pptxSviluppare Applicazioni Real Time con AppSync Deck.pptx
Sviluppare Applicazioni Real Time con AppSync Deck.pptxAmazon Web Services
 
API moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAPI moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e web
Amazon Web Services
 
MongoDB World 2016: Get MEAN and Lean with MongoDB and Kubernetes
MongoDB World 2016: Get MEAN and Lean with MongoDB and KubernetesMongoDB World 2016: Get MEAN and Lean with MongoDB and Kubernetes
MongoDB World 2016: Get MEAN and Lean with MongoDB and Kubernetes
MongoDB
 

Similar to mdevcon - A Primer to SyncAdapters (20)

Fire up your mobile app!
Fire up your mobile app!Fire up your mobile app!
Fire up your mobile app!
 
Build a Website on AWS for Your First 10 Million Users
Build a Website on AWS for Your First 10 Million UsersBuild a Website on AWS for Your First 10 Million Users
Build a Website on AWS for Your First 10 Million Users
 
MongoDB.local Berlin: App development in a Serverless World
MongoDB.local Berlin: App development in a Serverless WorldMongoDB.local Berlin: App development in a Serverless World
MongoDB.local Berlin: App development in a Serverless World
 
O365Con18 - Hybrid SharePoint Deep Dive - Thomas Vochten
O365Con18 - Hybrid SharePoint Deep Dive - Thomas VochtenO365Con18 - Hybrid SharePoint Deep Dive - Thomas Vochten
O365Con18 - Hybrid SharePoint Deep Dive - Thomas Vochten
 
R.A.P. (Rely on Android Platform)
R.A.P. (Rely on Android Platform)R.A.P. (Rely on Android Platform)
R.A.P. (Rely on Android Platform)
 
Windows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside worldWindows 8 Metro apps and the outside world
Windows 8 Metro apps and the outside world
 
Running Hybrid Cloud Patterns on AWS
Running Hybrid Cloud Patterns on AWSRunning Hybrid Cloud Patterns on AWS
Running Hybrid Cloud Patterns on AWS
 
Accelerate your Cloud Success with Platform Services
Accelerate your Cloud Success with Platform ServicesAccelerate your Cloud Success with Platform Services
Accelerate your Cloud Success with Platform Services
 
Introducing “Well-Architected” For Developers - Technical 101
Introducing “Well-Architected” For Developers - Technical 101Introducing “Well-Architected” For Developers - Technical 101
Introducing “Well-Architected” For Developers - Technical 101
 
SRV418 Deep Dive on Accelerating Content, APIs, and Applications with Amazon ...
SRV418 Deep Dive on Accelerating Content, APIs, and Applications with Amazon ...SRV418 Deep Dive on Accelerating Content, APIs, and Applications with Amazon ...
SRV418 Deep Dive on Accelerating Content, APIs, and Applications with Amazon ...
 
JUDCon 2014: Gearing up for mobile development with AeroGear
JUDCon 2014: Gearing up for mobile development with AeroGearJUDCon 2014: Gearing up for mobile development with AeroGear
JUDCon 2014: Gearing up for mobile development with AeroGear
 
Bridging the Gap Between Real Time/Offline and AI/ML Capabilities in Modern S...
Bridging the Gap Between Real Time/Offline and AI/ML Capabilities in Modern S...Bridging the Gap Between Real Time/Offline and AI/ML Capabilities in Modern S...
Bridging the Gap Between Real Time/Offline and AI/ML Capabilities in Modern S...
 
Code first in the cloud: going serverless with Azure
Code first in the cloud: going serverless with AzureCode first in the cloud: going serverless with Azure
Code first in the cloud: going serverless with Azure
 
Developing a provider hosted share point app
Developing a provider hosted share point appDeveloping a provider hosted share point app
Developing a provider hosted share point app
 
Spring Social - Messaging Friends & Influencing People
Spring Social - Messaging Friends & Influencing PeopleSpring Social - Messaging Friends & Influencing People
Spring Social - Messaging Friends & Influencing People
 
Build a Website on AWS for Your First 10 Million Users
Build a Website on AWS for Your First 10 Million UsersBuild a Website on AWS for Your First 10 Million Users
Build a Website on AWS for Your First 10 Million Users
 
Building SPA’s (Single Page App) with Backbone.js
Building SPA’s (Single Page App) with Backbone.jsBuilding SPA’s (Single Page App) with Backbone.js
Building SPA’s (Single Page App) with Backbone.js
 
Sviluppare Applicazioni Real Time con AppSync Deck.pptx
Sviluppare Applicazioni Real Time con AppSync Deck.pptxSviluppare Applicazioni Real Time con AppSync Deck.pptx
Sviluppare Applicazioni Real Time con AppSync Deck.pptx
 
API moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAPI moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e web
 
MongoDB World 2016: Get MEAN and Lean with MongoDB and Kubernetes
MongoDB World 2016: Get MEAN and Lean with MongoDB and KubernetesMongoDB World 2016: Get MEAN and Lean with MongoDB and Kubernetes
MongoDB World 2016: Get MEAN and Lean with MongoDB and Kubernetes
 

Recently uploaded

UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
Uni Systems S.M.S.A.
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
nkrafacyberclub
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
Alan Dix
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
BookNet Canada
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
KatiaHIMEUR1
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
Aftab Hussain
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
ThomasParaiso2
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
Guy Korland
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
DianaGray10
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
SOFTTECHHUB
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
Alpen-Adria-Universität
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
Kari Kakkonen
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Nexer Digital
 

Recently uploaded (20)

UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
Microsoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdfMicrosoft - Power Platform_G.Aspiotis.pdf
Microsoft - Power Platform_G.Aspiotis.pdf
 
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptxSecstrike : Reverse Engineering & Pwnable tools for CTF.pptx
Secstrike : Reverse Engineering & Pwnable tools for CTF.pptx
 
Epistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI supportEpistemic Interaction - tuning interfaces to provide information for AI support
Epistemic Interaction - tuning interfaces to provide information for AI support
 
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...Transcript: Selling digital books in 2024: Insights from industry leaders - T...
Transcript: Selling digital books in 2024: Insights from industry leaders - T...
 
Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !Securing your Kubernetes cluster_ a step-by-step guide to success !
Securing your Kubernetes cluster_ a step-by-step guide to success !
 
Removing Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software FuzzingRemoving Uninteresting Bytes in Software Fuzzing
Removing Uninteresting Bytes in Software Fuzzing
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...GridMate - End to end testing is a critical piece to ensure quality and avoid...
GridMate - End to end testing is a critical piece to ensure quality and avoid...
 
GraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge GraphGraphRAG is All You need? LLM & Knowledge Graph
GraphRAG is All You need? LLM & Knowledge Graph
 
UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5UiPath Test Automation using UiPath Test Suite series, part 5
UiPath Test Automation using UiPath Test Suite series, part 5
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
Why You Should Replace Windows 11 with Nitrux Linux 3.5.0 for enhanced perfor...
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Video Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the FutureVideo Streaming: Then, Now, and in the Future
Video Streaming: Then, Now, and in the Future
 
DevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA ConnectDevOps and Testing slides at DASA Connect
DevOps and Testing slides at DASA Connect
 
Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?Elizabeth Buie - Older adults: Are we really designing for our future selves?
Elizabeth Buie - Older adults: Are we really designing for our future selves?
 

mdevcon - A Primer to SyncAdapters

  • 1. A PRIMER TO SYNC ADAPTERS Kiana Tennyson mdevcon Tuschinski Theater March 2013
  • 2. OVERVIEW v Who is Kiana? v SyncAdapter Use Cases v The Big Picture v Configuration v Authorization, Content, Synchronization v Wrap up/Questions
  • 3. WHO’S KIANA? v Software Developer v Professional background working on web portals v Work at Manheim, wholesale vehicle auction company v Customer facing applications •  Web portal (www.manheim.com) Ruby, Java, JS •  iOS app •  Android app
  • 4. SYNC ADAPTERS ARE…? v Share data between a remote data source and an Android device v Android OS provides plug-in architecture that takes care of: •  Coordinating network availability with syncing all datasources •  Scheduling synchronization/Handling stopped processes •  Accommodating user preferences when syncing •  Handling network interruptions
  • 5. TOUGH PARTS v Good news! Writing a Custom SyncAdapter is actually easy! v Bad news. There are potentially tough parts: •  Authentication Handling •  (Custom) Content Provider •  Data Handling v Defined by business rules
  • 6. BEST USE CASES Application that… v Requires authentication step to connect to remote datasource v Potentially could use a built-in ContentProvider •  All providers found in android.provider package v Application Suite backed by custom ContentProvider
  • 7. !(BEST USE CASES) v Anything that DOES NOT require a login v Any source that provides an RSS feed •  Typically public data sources like news/media sites •  Write a parser that reads the feed only when the user wants it •  SyncAdapter not necessary to write to the ContentProvider v If Service does not constantly need to run in the background •  User has limited battery power, code with this in mind
  • 8. A Primer to SyncAdapters CONFIGURATION
  • 9. THE BIG PICTURE AccountManager SyncManager ContentProvider •  Requires •  Uses Account •  Holds the data Authentication List as a basis for •  Called in Service to add it’s Sync List onPerformSync() Account •  Requires Sync •  Adds Account to Service to start Account List data syncs
  • 10. AUTHENTICATION v Write an AuthActivity •  serves UI for user to enter account info •  Write it to complete the authorization process v Write an Authenticator •  MUST extend AbstractAccountAuthenticator •  Returns the AuthActivity in a Bundle object v Write an Authentication Service •  MUST extend Service •  onBind return IBinder for the Authenticator
  • 11. SYNCHRONIZATION v Write a SyncAdapter •  MUST extend AbstractThreadedSyncAdapter •  Overwrite onPerformSync() v Write a Sync Service •  MUST extend Service •  Allow creation of ONE SyncAdapter •  onBind returns a IBinder for SyncAdapter
  • 12. RESOURCE XMLS v Provide configuration info v Map account type to objects •  SyncAdapter and Authenticator are connected via android:accountType v Map content authority to SyncAdapter
  • 13. RESOURCE XMLS <?xml version="1.0" encoding="utf-8"?>! <account-authenticator xmlns:android="http:// !schemas.android.com/apk/res/android”! android:accountType=”your.uniquename.here"! android:icon="@drawable/icon"! android:smallIcon="@drawable/icon"! android:label="@string/label"! />!
  • 14. Add Account v  Notice result of android:icon v  Green lights – Account added v  Gray lights – Account not added v  Clicking one launches Auth Activity interface
  • 15. RESOURCE XMLS <?xml version="1.0" encoding="utf-8"?>! <sync-adapter xmlns:android="http:// !schemas.android.com/apk/res/android”! android:contentAuthority="com.android.contacts"! android:accountType="your.uniquename.here"! android:supportsUploading="false"! android:userVisible="true"! />!
  • 16. MANIFEST v Several appropriate permissions v Declare AuthenticationService with <service> tag •  Intent filter: “android.accounts.AccountAuthenticator” •  Meta-data tag points AccountAuthenticator to xml resource file v Declare SyncService with <service> tag •  Intent filter: “android.content.SyncAdapter” •  Meta-data tag points SyncAdapter to xml resource file •  Other Meta-data tag defines custom MIME-types v Declare AuthActivity (no Intent filter necessary)
  • 17. MANIFEST.XML <service android:name=".authenticator.AuthenticationService” !android:exported="true”>! <intent-filter>! <action android:name="android.accounts.AccountAuthenticator" />! </intent-filter>! <meta-data android:name="android.accounts.AccountAuthenticator”! !android:resource="@xml/authenticator" />! </service>! <service android:name=".syncadapter.SyncService” android:exported="true">! <intent-filter>! <action android:name="android.content.SyncAdapter" />! </intent-filter>! <meta-data android:name="android.content.SyncAdapter”! !android:resource="@xml/syncadapter" />! <meta-data android:name="android.provider.CONTACTS_STRUCTURE”! !android:resource="@xml/contacts" />! </service>!
  • 18. WHY SERVICES? v SyncAdapter is bound to a service, Authentication is bound to a service… but why? v SyncManager finds all syncAdapters via a SyncAdaptersCache. v AccountManager finds all Accounts via AccountAuthenticatorCache v RegisteredServicesCache •  Reads the XML files created (account-authenticator and syncadapter) •  Generates service maps
  • 19. CODE SUMMARY v Create a syncadapter.xml file v Create an authenticator.xml file v Add an authentication <service> to manifest v Add a sync <service> to manifest v Add correct permissions to manifest v Write some java… but what does any of this mean?
  • 20. A Primer to SyncAdapters THE DATA
  • 21. ACCESSING CONTENT •  SharedPreferences Data Storage •  External Storage •  SQLLiteDatabase ContentProvider ContentProviderClient ContentResolver Context Android Application(s) The Device User
  • 22. CONTENT PROVIDER v Manages central repository of data. v SyncAdapters wouldn’t exist without ContentProviders •  SyncAdapter mentioned in ContentProvider section of API Guide v Built in ContentProviders contain a SyncState table •  Use to store sync state, meta-data or any sync related data v Sync related columns in other tables: •  DIRTY, VERSION, SOURCE_ID
  • 23. IMPORTANT COLUMNS v DIRTY (local modifications) •  Indicates data row has been changed locally since last sync. •  When SyncAdapter adds/updates a row, append “CALLER_IS_SYNCADAPTER” to Content URI v VERSION •  Incremented by Provider whenever the data row is changed. •  High-water marking (aka lastSyncState) v SOURCE_ID •  Unique ID for data row (primary key on the remote datasource) •  If set to null, indicates to SyncAdapter to create new row on remote source
  • 24. CUSTOM CONTENT PROVIDER v What properties make the built-in ContentProviders “syncable”? •  Extra “For Sync use only” table that holds metadata •  “CALLER_IS_SYNCADAPTER” query param •  Use of “high-water-mark” is essential v These properties should be applied to Custom SyncAdapter
  • 25. CONTENT RESOLVER VS CONTENTPROVIDER CLIENT ContentResolver ContentProviderClient v  Thread safe v  Not thread safe v  Many calls to many v  Repeated calls to same CA ContentAuthorities (CA) v  Cheaper call (one CA lookup) v  Expensive call (Many CA lookups) v  You MUST call release() to avoid v  Resolver contains a Client memory leak
  • 26. CONTENTPROVIDER CLIENT v Part of onPerformSync() method signature. v Not thread safe, so be careful with usage •  Utilize locking strategies, ensure no outside services are performing activities on sync-candidate data v Android Sample project uses threadsafe ContentResolver via a Manager
  • 27. CONTENT RESOLVER v Do I really need this? Your choice. •  ContentResolvers query the ContentProvider •  Use it to CRUD data inside syncAdapter.onPerformSync(); •  SampleSyncAdapter uses the ContentResolver by way of it’s ContactsManager class, because it performs batch operations v Retrieve it using: context.getContentResolver(); v However, there are other ways to access the data
  • 28. DATA CONSIDERATIONS v Determine structure of serialized/transmitted data •  Using json? xml? yaml? •  What does a single row (data unit) look like? v How does the server parse and save the transmitted data? •  Likely defined by business limitations. v How does the device parse/save the data? •  ContentProviderClient or ContentResolver (batch ops)
  • 29. A Primer to SyncAdapters AUTHENTICATION
  • 30. ACCOUNT v Account object contains an Account name and Account type. •  Note, the Account object does NOT contain a password •  Example: user has multiple twitter accounts v AccountManager maps an Account object to it’s “password” v Recommended strategy: store Account and authToken on device •  SampleSyncAdapter project stores password (possible human error) v SyncManager can only schedule syncs per Account
  • 31. ACCOUNT MANAGER v Contains centralized registry of user’s online accounts v Used to determine list of data sources to be synced •  AccountManager provides list of Accounts •  SyncManager grabs the list of Accounts for syncing v AccountAuthenticatorCache maps accountType to objects extending AbstractAccountAuthenticator v Android Component; you don’t write this
  • 32. AUTHENTICATION v User chooses to Add an Account •  List compiled from array of allowable account types v System chooses Authenticator based on “android:accountType” •  Binds to a Service which returns the Authenticator’s IBinder v Authenticator’s overridden addAccount() method is called •  Ultimately the Login UI displays, new Account is created
  • 33. AUTHENTICATOR v Allows developer to implement authentication •  Per remote service v Must extend AbstractAccountAuthenticator •  Responds to an intent “android.accounts.AccountAuthenticator” advertised by the AccountManager for it’s accountType only. v Authentication Service returns a Binder to your implemented AbstractAccountAuthenticator v addAccount() returns bundle with intent containing Activity
  • 34. ADD ACCOUNT Sample SyncAdapter Activity Example Activity
  • 35. A Primer to SyncAdapters THE SYNC
  • 36. SYNCMANAGER v Responsible for scheduling, cancelling syncs. •  Maintains a list of active syncs (mActiveSyncContext) v Sync handling strategy very tightly coupled to Accounts •  Account is part of most SyncManager methods v How do the SyncHandler and Account interact? •  SyncHandler receives a message containing an ActiveSyncContext. ActiveSyncContext contains all information about the sync that needs to begin including the Account.
  • 37. SYNCHRONIZATION v SyncManager contains ONE SyncHandler v SyncHandler’s job: receive/handle sync operation messages •  On receiving a Connection Message, calls startSync for the syncAdapter in question •  startSync() spins up a new SyncThread •  The method onPerformSync() that was implemented is invoked when run() is invoked on the thread
  • 38. SYNC ADAPTER v Where the main party happens. The method onPerformSync() gets called within a syncThread.run() v Make use of the DIRTY/VERSION/SOURCE_ID rows v Instantiate like any class. •  However, create only one for thread safety.
  • 39. ONPERFORMSYNC() v What should I do in the onPerformSync() method? v Merge remote data with local data •  DIRTY/VERSION/SOURCE_ID columns v Use business rules to determine order of operations •  Whether local data overwrites remote data or vice versa v Implement a remote connection strategy to access remote data
  • 41. WRAP UP v We learned… •  What SyncAdapters are •  Set up •  Content (ContentProvider/data characteristics) •  Authorization (Accounts, Account Management) •  Synchronization (SyncManager, SyncService) •  Debugging/Dev Tools
  • 42. A Primer to SyncAdapters QUESTIONS?