D
D
Dmtm2019-08-30 07:46:04
Android
Dmtm, 2019-08-30 07:46:04

How to get Result.failure() from Worker?

I can't use Observer, only ListenableFuture
There is a comment in the sources The {@link State.FAILURE} state will come through as a {@link Throwable} on the {@link ListenableFuture}.
But where to intercept this Throwable is not clear.

val request = OneTimeWorkRequest.Builder(MyWorker::class.java)
            .build()

        val result = WorkManager.getInstance(App.instance).enqueue(request)
try {
        result.result.addListener({

            },
            {it.run()})
} catch (e: Throwable) {
         e.printStackTrace()
        }

wrapping in try/catch doesn't help

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question