A Kotlin Work Manager library for Android that includes notifications and Hilt support.

User guide

  1. Add the JitPack repository to your project’s build.gradle
allprojects { repositories { ... maven { url 'https://jitpack.io' } }
  1. Add the plugins kapt and hilt to the build.gradle file of your app at the top
apply plugin: 'kotlin-kapt'
apply plugin: 'dagger.hilt.android.plugin'
  1. Add the dependencies for Boot Laces & Hilt to your app’s build.gradle
dependencies { implementation 'com.github.evilthreads669966:bootlaces:8.4' implementation "com.google.dagger:hilt-android:2.29.1-alpha" kapt "com.google.dagger:hilt-android-compiler:2.29.1-alpha"
  1. Add the Hilt plugin to the build.gradle dependencies of your project
dependencies { ... classpath "com.google.dagger:hilt-android-gradle-plugin:$hilt_version"
  1. Comment out your subclass of the application class
@HiltAndroidAppclass App: Application()
  1. Add the name of your application subclass to the manifest
<application android:name=".App" ...
  1. Create your employees. The description parameter is used for your notification. You can create a broadcast receiver for your worker by overriding onReceive an action to worker.
class MyWorker: Worker(66,"Something evil") { override val receiver: WorkReceiver? get() = null override suspend fun doWork(ctx: Context) { for(i in 1..10) delay(1000) }
}//if you want to add a BroadcastReceiver to your workerclass WorkerWithReceiver: Worker(666,"Locking the screen"){ override val receiver: WorkReceiver? get() = object : WorkReceiver(Intent.ACTION_CLOSE_SYSTEM_DIALOGS) { override fun onReceive(ctx: Context?, intent: Intent?) { //do something } } override suspend fun doWork(ctx: Context) { //do work }
}//worker with a progress notificationclass MyProgressWorker: Worker(66,"Working while displaying a notification for progress", withNotification = true) { override val receiver: WorkReceiver? get() = null override suspend fun doWork(ctx: Context) { for(i in 1..10) delay(1000) }
  1. Inject your WorkScheduler into an Android context
@Inject lateinit var scheduler: WorkScheduler
  1. Schedule your employees
//persistent worker
scheduler.schedulePersistent(WorkerWithReceiver())//one time worker
scheduler.scheduleOneTime(MyWorker())//one time worker with notificaton for displaying progress. This works for all scheduler methods
scheduler.scheduleOneTime(MyProgressWorker())//periodic worker
scheduler.schedulePeriodic(10000, MyWorker()) //runs task every 10 seconds and persists through reboot//future worker
scheduler.scheduleFuture(5000, MyWorker()) //runs task once in 5 seconds and persists through reboot if device is restarted before//hourly worker
scheduler.scheduleHourly(MyWorker()) //runs task once every hour and persists through reboot//daily worker
scheduler.scheduleDaily(MyWorker()) //runs task once every day and persists through reboot//weekly worker
scheduler.scheduleWeekly(MyWorker()) //runs task once every week (7 days) and persists through reboot//monthly worker
scheduler.scheduleMonthly(MyWorker()) //runs task once every month and persists through reboot//yearly worker
scheduler.scheduleYearly(MyWorker()) //runs task once every year and persists through reboot

Important to know


Copyright 2019 Chris Basinger
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.


Please enter your comment!
Please enter your name here