Resume an interrupted synchronization where partial data has been downloaded to the device.
SMP101DB.resumePendingSynchronization();
SMP101DB.cancelPendingSynchronization();
... ... ... //turn on the resume synchronization option SMP101DB.getSynchronizationProfile().setResumeSynchronization(true); MyCallbackHandlerForResumeSync callback = new MyCallbackHandlerForResumeSync(); SMP101DBRegisterCallbackHandler(callback); MyResumeSyncStatusListener listener = new MyResumeSyncStatusListener(); GenericList<SynchronizationGroup> groups = new GenericList<SynchronizationGroup>(); groups.add(SMP101DB.getSynchronizationGroup("default")); //submit a non-blocking sync request SMP101DB.beginSynchronize(groups, null, false, listener);
//in the implementation of SUPDefaultCallbackHandler class ... ... ... int onSynchronize(GenericList<SynchronizationGroup> groups, SynchronizationContext context) { switch (context.getStatus()) { ... case SynchronizationStatus.INTERRUPTED_WITH_PARTIAL_DATA: _isInterruptedWithPartialData = true; // By returning continue, the system waits for a request to resume or cancel the pending synchronization and the synchronization queue is locked. // If returning SynchronizationAction.CANCEL instead, the system automatically cancels the pending synchronization. // Application cannot resume the synchronization and the synchronization queue is not locked. return SynchronizationAction.CONTINUE; ... } }
void handleInterruptedWithPartialData() { if (MAX_INTERRUPTED_STATUS == _interruptedStatusCount) { cancelPendingSync(); System.out.println("Resume sync is canceled."); System.out.println("Interrupted status count reached the max: " + MAX_INTERRUPTED_STATUS + "."); } else { _isInterruptedWithPartialData = true; _interruptedStatusCount++; int waitCount = 0; while(!_isDeviceConnectedToInternet) { Thread.sleep(1000); waitCount++; if (waitCount > MAX_WAIT) { System.out.println("There is no network connection " + MAX_WAIT + " seconds."); break; } } if (_isDeviceConnectedToInternet) { resumeSync(); } else { cancelPendingSync(); System.out.println("Resume sync is canceled."); System.out.println("there's no network connectivity for too long."); } } } void cancelPendingSync() { System.out.println("going to cancel pending sync..."); if (SMP101DB.cancelPendingSynchronization()) { System.out.println("failed to cancel pending sync."); } else { System.out.println("pending sync has been cancelled."); } } void resumeSync() { if (!_isInterruptedWithPartialData) { System.out.println("no resume as there is no interrupted with partiald data."); return; } System.out.println("going to resume sync..."); bool resumed = SMP101DB.resumePendingSynchronization(); _isInterruptedWithPartialData = false; if (!resumed) { System.out.println("failed to resume pending syn."); } else { _resumeSyncCount++; System.out.println("resume sync count: " + _resumeSyncCount + "."); } }