Sync Adapter not calling onCreate

2019-06-14 18:13发布

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

1条回答
何必那么认真
2楼-- · 2019-06-14 19:04

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 .

查看更多
登录 后发表回答