Skip to content

Migrating to WorkManager

Ralf Wondratschek edited this page Sep 24, 2018 · 2 revisions

For new projects it's recommended to use WorkManager instead of android-job for various reasons. At some point in the future android-job will be deprecated. Migrating an existing app to WorkManager isn't difficult and only requires a few steps.

Using both libraries in parallel

You can use both libraries in parallel without any issues. Furthermore, starting with version 1.3.0 android-job uses WorkManager as job scheduling engine under the hood, if the architecture component can be found at runtime. It's only necessary do add WorkManager to your dependencies.

dependencies {
    implementation "android.arch.work:work-runtime:$work_version"
}

If you want to opt-out of this behavior (not recommended), then you can turn the API off:

JobConfig.setApiEnabled(JobApi.WORK_MANAGER, false);

Removing android-job

The API of WorkManager is very similar to the one of android-job, what makes the migration easy. Once you removed all dependencies in code to android-job you can remove the dependency itself.

The library uses a shared preference file and a database for storing jobs and other information. It's not necessary to delete these file, but in case you'd like to free some bytes, you can delete following files in the respective folders

evernote_jobs.xml // pref file
evernote_jobs.db // database file

It's possible to query the database file and copy existing jobs over to WorkManager. However, the easier and recommended approach is to schedule new workers as with a fresh install of the app. It's not necessary to cancel any alarms or jobs that were scheduled through android-job. The system will clear them automatically.

Clone this wiki locally