Reliably Complete Background Work with WorkManager

The WorkManager library/API is a great way to schedule tasks that should run in the background and complete even if the app is closed or the device is restarted. WorkManager will handle the tasks it’s given in a way that the OS can handle, meaning that older versions of the Android OS can still use the library using existing features. This gives us a higher level of backward compatibility in our app without needing to worry about implementation details.

I’ll show you how to implement a Worker, which will be used by WorkManager to back up Settings. Once we’re done there, I’ll highlight a few of the other features WorkManager can offer for other use cases. Add in the WorkManager dependency:

Get Kotlin and Android Development featuring Jetpack now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.