का उपयोग करते समय प्रारंभिक रूप से समन्वयित करने के लिए सिंक एडाप्टर को रोकें, मैं अपने प्रोजेक्ट में एक सिंक एडाप्टर का उपयोग कर रहा हूं जो समय-समय पर सिंक हो जाएगा। सिंक एडाप्टर के लिए खाता बनाने के लिए मैं नीचे दिए गए कोड का उपयोग कर रहा हूं।addPeriodicSync
मुझे जिस समस्या का सामना करना पड़ रहा है वह यह है कि यह कोड प्रारंभिक सिंक ट्रिगर कर रहा है। प्रलेखन में कोई उल्लेख नहीं किया गया है कि यह कोड सिंक को प्रारंभ में चलाने के लिए बनाएगा।
वास्तव में यहां तक कि Google नमूना प्रोजेक्ट में भी प्रारंभिक सिंक को ट्रिगर करने के लिए अतिरिक्त कोड है जिसे मैंने हटा दिया है।
मैं इस नमूने से कोड का इस्तेमाल किया है: http://developer.android.com/samples/BasicSyncAdapter/index.html
यहां तक कि अगर मैं आदेश ContentResolver.cancelSync (खाते, नल) जोड़ने; सिंक एडाप्टर अभी भी चलाता है।
मैं सिंक एडाप्टर को प्रारंभ में सिंक करने से कैसे रोक सकता हूं। सिंक अंतराल अवधि बीत जाने पर पहली बार सिंक करना चाहिए।
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);
}