Search code examples
androidandroid-intentandroid-activityandroid-serviceandroid-syncadapter

Sync Adapter not calling onCreate


Do we need to start the Sync Adapter service or framework starts implicitly? I have put a log on Constructor, onCreate, onDestroy of Sync Adapter service and when I start the app, I don't see the logs in the logcat.

But when I do on activity onCreate

Intent serviceIntent = new Intent(context, SyncService.class);
context.startService(serviceIntent);

I see the logs.

Please suggests.

Cheers, Raj


Solution

  • Sync adapter starts explicitly by calling:

    ContentResolver.requestSync(ACCOUNT, AUTHORITY, null);
    

    or similar method:

    ContentResolver.addPeriodicSync(
                ACCOUNT,
                AUTHORITY,
                Bundle.EMPTY,
                SYNC_INTERVAL);
    

    https://developer.android.com/training/sync-adapters/running-sync-adapter.html

    I strongly recommend this book, especially first 200 pages http://www.wrox.com/WileyCDA/WroxTitle/Enterprise-Android-Programming-Android-Database-Applications-for-the-Enterprise.productCd-1118183495.html .