Search code examples
androidandroid-syncadapterandroid-workmanager

Should a WorkManager be used with a SyncAdapter?


Previously one could assure a series of updates using an IntentService or SyncAdapter w/ a WakeLock.

Now with the new Doze mode, and limitations to save battery, is WakeLock still reliable enough, or should longer processes be started in the IntentService or SyncAdapter using WorkManager?

Also is WorkManager api production-ready?


Solution

  • As far as I understand it, the WorkManager can replace IntentService and SyncAdapter completely. E.g. everything you're doing in SyncAdapter.onPerformSync() can now be in WorkManager.doWork().

    It got a stable release 2.4.0 and is ready for production.

    Regarding wake locks: In Android 8.0 there is the following change:

    As one of the changes that Android 8.0 (API level 26) introduces to improve battery life, when your app enters the cached state, with no active components, the system releases any wakelocks that the app holds.

    So I wouldn't rely on wake locks anymore. I think they will be completely removed in future Android versions. And most of the time you don't need them with the WorkManager.