I have been digging into ListenableWorker
class to create a service using new workmanager. But nowhere have i found any examples. Any source which describes work manager, gives example of Worker
class which has a nice doWork
method but it doesn't meet my requirements. So i want your help to write a nice service using ListenableWorker
which can handle ListenableFuture
I have tried android developer's documentation and in their documentation, they have written about using guava and using concurrent-futures both of which don't provide any example to write a simple service. I also have watched the workmanager release video in which google engineers explain the new API but their examples are all in Kotlin and i don't get the classes to use.
import android.content.Context;
import androidx.annotation.NonNull;
import androidx.concurrent.futures.CallbackToFutureAdapter;
import androidx.work.ListenableWorker;
import androidx.work.WorkerParameters;
import com.google.common.util.concurrent.ListenableFuture;
public class DistanceWorker extends ListenableWorker {
public DistanceWorker(Context context, WorkerParameters workerParameters){
super(context, workerParameters);
}
@NonNull
@Override
public ListenableFuture<Result> startWork() {
//what to write here ?
}
}
I just want to return a future and want to know how to resolve or reject that future when my work is done. Please help me understanding it.