I am using sync adapter to sync between my mobile device to my central server. When I add a record to my sqlite DB on the device, I am using requestSync to sync with server and it is working well. Even when there is no internet connection with server, I am able to force re-sync later by catching the ParseException and incrementing syncResult.stats.numParseExceptions in the SyncAdapter's' onPerformSync.
My problem is if i switch-off my device before sync is complete. No sync is attempted when i turn device on again. What can I do to ensure sync is attempted when I turn device on again?
My code:
UI activity --> on Save Button Click event handler
ContentResolver.requestSync(createDummyAccount() DatabaseContract.AUTHORITY , settingsBundle);
//SyncAdapter -->> onPerformSync()
Client client = ClientBuilder.newClient();
client.property(ClientProperties.CONNECT_TIMEOUT, 6000);
WebTarget target = client.target(SERVICE_URL);
try {
String callResult = target
.request(MediaType.APPLICATION_XML)
.put(Entity.entity(form,
MediaType.APPLICATION_FORM_URLENCODED_TYPE),
String.class);
System.out.println("response: " + callResult);
} catch (ProcessingException pe) {
syncResult.stats.numIoExceptions++;
syncResult.delayUntil = 60;
}