I try to understand the Android synchronization logic. What I don't understand is the file syncadapter.xml
contained in the Android SDK sample project SampleSyncAdapter
. If you downloaded the SDK samples it should be in the following folder:
SDK/android-sdk-PLATFORM/samples/android-VERSION/SampleSyncAdapter/res/xml/syncadapter.xml
I read, the authority of a content provider should be a string or a reference to a resource. What exactly is the content authority and where is com.android.contacts
? Here is the content of the file (w/o license information and comments, API level 16).
<sync-adapter xmlns:android="http://schemas.android.com/apk/res/android" android:contentAuthority="com.android.contacts" android:accountType="com.example.android.samplesync" android:supportsUploading="false" android:userVisible="true" />
The main() method is in the Android framework class android. app. ActivityThread . This method creates the Main (UI) Thread , sets up a Looper on it and starts the event loop.
Offline sync allows end users to interact with a mobile app—viewing, adding, or modifying data—even when there's no network connection. Changes are stored in a local database. Once the device is back online, these changes are synced with the remote backend.
The Sync apps are available for Android, iPhone and iPad, and make it easy for you to access your files right from your mobile device. The Sync apps are free, and provide the following features: Access your files in Sync from anywhere. Use third-party apps on your device to open and edit files in Sync.
The sync adapter component in your app encapsulates the code for the tasks that transfer data between the device and a server. Based on the scheduling and triggers you provide in your app, the sync adapter framework runs the code in the sync adapter component.
Allows your app to read the current sync adapter settings. For example, you need this permission in order to call getIsSyncable () . Allows your app to control sync adapter settings. You need this permission in order to set periodic sync adapter runs using addPeriodicSync ().
Use the constructors to run setup tasks each time your sync adapter component is created from scratch, just as you use Activity.onCreate () to set up an activity. For example, if your app uses a content provider to store data, use the constructors to get a ContentResolver instance.
* Specify the code you want to run in the sync adapter. The entire * up your own background processing. * Put the data transfer code here. * Specify the code you want to run in the sync adapter. The entire * up your own background processing. * Put the data transfer code here.
There are two basic methods you can use when making a SyncAdapter:
The former is what's going on in this example app. They have some website that has a list of contacts, and they want to store those along with the other contacts on the device. In either case, the way this all works is through a relationship between three components:
An Android device can have many different ContentProviders and many different SyncAdapters. Since a ContentResolver may not be part of the same .apk as a SyncAdapter, ContentResolver is a system service that finds the right ContentProvider to store a given kind of data. It does this using the ContentAuthority string, which uniquely identifies one specific ContentProvider. Moreover, each ContentProvider must be declared in AndroidManifest.xml
which ensures that it can be found by the ContentResolver. Within this declaration you can specify whether the ContentProvider can be used by other applications, see: android:exported
.
<provider android:name=".CustomProvider" android:authorities="com.example.app.provider" android:exported="false" android:multiprocess="true" > </provider>
In this case, using an existing ContentProvider, you will need to look at the platform documentation to see what ContentAuthority string they use, and use the same string. If you're creating your own ContentProvider, you just need to ensure that the ContentAuthority you create is unique. The best way to do this is to use parts of your domain name (java class style) in the Authority. Write them in the reverse order. This is illustrated in their example... com.android.contacts
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With