'How to call at object with callback/listener in a Worker doWork() method of the
I'm am trying to use a WorkManager to schedule an API call because of my apps offline capability, but I am not sure how to handle listeners in my worker. Inside the ScenarioRunSyncHelper it builds the JsonObject and calls a WebApi class which refreshes an authentication token if required. So there are two layers of listeners. It looks like some of the other examples I have seen like here and here there are no callbacks/listeners in the doWork. Their objects/methods within the doWork method throw errors so the Result.success or Result.failure can be called accordingly. Mine looks like this:
@NonNull
@Override
public Result doWork() {
ScenarioRunSyncHelper helper = new ScenarioRunSyncHelper();
helper.sync(application, scenarioRun, new ScenarioRunSyncHelper.SyncListener() {
@Override
public void onSuccess() {
//return Result.success();
}
@Override
public void onError(Exception e) {
//return Result.failure();
}
});
return Result.success();
}
Is this accurate? Is anybody else facing this issue?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
