无法解析 ListenableWorker 中的符号 'CallbackToFutureAdapter'
Cannot Resolve symbol 'CallbackToFutureAdapter' in ListenableWorker
我正在根据 this official documentation from google
实现一个 ListenableWorker class
我收到以下错误无法解析符号 'CallbackToFutureAdapter'
下面是我尝试实现的方法
return CallbackToFutureAdapter.getFuture(completer -> {
Callback callback = new Callback() {
int successes = 0;
@Override
public void onFailure(Call call, IOException e) {
completer.setException(e);
}
@Override
public void onResponse(Call call, Response response) {
++successes;
if (successes == 100) {
completer.set(Result.success());
}
}
};
completer.addCancellationListener(cancelDownloadsRunnable, executor);
for (int i = 0; i < 100; ++i) {
downloadAsynchronously("https://www.example.com", callback);
}
return callback;
});
我应该导入什么来解析 CallbackToFutureAdapter 我已经在我的应用级别 Android X 中实现了 gradle
只需添加以下导入:
implementation "androidx.concurrent:concurrent-futures:1.1.0"
我正在根据 this official documentation from google
实现一个 ListenableWorker class我收到以下错误无法解析符号 'CallbackToFutureAdapter'
下面是我尝试实现的方法
return CallbackToFutureAdapter.getFuture(completer -> {
Callback callback = new Callback() {
int successes = 0;
@Override
public void onFailure(Call call, IOException e) {
completer.setException(e);
}
@Override
public void onResponse(Call call, Response response) {
++successes;
if (successes == 100) {
completer.set(Result.success());
}
}
};
completer.addCancellationListener(cancelDownloadsRunnable, executor);
for (int i = 0; i < 100; ++i) {
downloadAsynchronously("https://www.example.com", callback);
}
return callback;
});
我应该导入什么来解析 CallbackToFutureAdapter 我已经在我的应用级别 Android X 中实现了 gradle
只需添加以下导入:
implementation "androidx.concurrent:concurrent-futures:1.1.0"