Skip to content

Instantly share code, notes, and snippets.

@avianey
Created April 9, 2021 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avianey/5ac103f9281660f419768dba8108f79e to your computer and use it in GitHub Desktop.
Save avianey/5ac103f9281660f419768dba8108f79e to your computer and use it in GitHub Desktop.
JobIntentService crashing with java.lang.RuntimeException: An error occurred while executing doInBackground()
package androidx.core.app
abstract class JobIntentServiceInternal: JobIntentService() {
/**
* Returns a GenericWorkItem that will fail silently to complete
* if it has been cancelled while executing inside
* the JobIntentService$CommandProcessor#doInBackground loop
* or if dequeue fails
*/
override fun dequeueWork(): GenericWorkItem? {
try {
val item = super.dequeueWork()
if (item != null) {
return object : GenericWorkItem {
override fun getIntent() = item.intent
override fun complete() {
try {
item.complete()
} catch (ignore: Exception) {}
}
}
}
} catch (ignore: Exception) {}
return null
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment