I am using a sync adapter in my project that will periodically sync. To create an account for the sync adapter, I use the code below.
The problem I am facing is that this code starts the initial synchronization. There is no mention in the documentation that this code will make the synchronization work first.
In fact, even in the Google sample project, there is additional code to start the initial synchronization, which I deleted.
I used the code from this example: http://developer.android.com/samples/BasicSyncAdapter/index.html
Even if I add the command ContentResolver.cancelSync (account, null); the sync adapter is still working.
How can I sync the sync adapter first. It must be synchronized for the first time when the period of the synchronization interval has passed.
Account account = new Account(context.getPackageName(), context.getPackageName()); AccountManager accountManager = (AccountManager) context.getSystemService(Context.ACCOUNT_SERVICE); if (accountManager.addAccountExplicitly(account, null, null)) { // Inform the system that this account supports sync ContentResolver.setIsSyncable(account, context.getPackageName(), 1); // Inform the system that this account is eligible for auto sync when the network is up ContentResolver.setSyncAutomatically(account, context.getPackageName(), true); // Recommend a schedule for automatic synchronization. // The system may modify this based // on other scheduled syncs and network utilization. ContentResolver.addPeriodicSync(account, context.getPackageName(), Bundle.EMPTY, AppConstants.SYNC_INTERVAL); }
android android-contentresolver android-syncadapter
zaphod100.10
source share