android - Stop sync adapter to sync initially when using addPeriodicSync -
i using sync adapter in project sync periodically. create account sync adapter using below code.
the issue facing code triggering initial sync. documentation has no mentioned code make sync run initially.
in fact in google sample project there code triggering initial sync have removed.
i have used code sample: http://developer.android.com/samples/basicsyncadapter/index.html
even if add command contentresolver.cancelsync(account, null); sync adapter still runs.
how can stop sync adapter syncing initially. should sync first time when sync interval period 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 system account supports sync contentresolver.setissyncable(account, context.getpackagename(), 1); // inform system account eligible auto sync when network contentresolver.setsyncautomatically(account, context.getpackagename(), true); // recommend schedule automatic synchronization. // system may modify based // on other scheduled syncs , network utilization. contentresolver.addperiodicsync(account, context.getpackagename(), bundle.empty, appconstants.sync_interval); }
you can schedule future event after first time manual sync.
private static final scheduledexecutorservice scheduler = executors.newscheduledthreadpool(1); private void setdelayedautosync() { scheduledfuture<?> countdown = scheduler.schedule(new runnable() { @override public void run() { log.d(tag, "out of time!"); contentresolver.setsyncautomatically(account, content_authority, true); contentresolver.addperiodicsync(account, content_authority, new bundle(),sync_frequency_constant); }, sync_frequency_constant, timeunit.seconds); }
Comments
Post a Comment