我需要等待侦听器检查图像是否正确发送,然后完成AsyncTask
。但是logcat
的最后登录为“ blocking ...”,因此onComplete永远不会触发。
当我将条件变量的初始化设置为true时,它正在工作,但没有等待block()。我在ConditionVariable
上看到了许多示例,但我无法弄清楚我的错误在哪里,它应该可以工作。
private static class SendImageTask extends AsyncTask<SendImagePojo, Void, String> {
private String KOFAX_TAG = "kofax";
@Override
protected String doInBackground(SendImagePojo... params) {
Log.d(KOFAX_TAG, "doInBackground");
final ConditionVariable condition = new ConditionVariable(false);
params[0].kfx.sendImageService(params[0].doc, params[0].s, params[0].img, params[0].imageIndex, true, new ICompletionListener<Void>() {
@Override
public void onComplete(Void aVoid, Exception e) {
Log.d(KOFAX_TAG, "onComplete");
if (e != null) {
Log.e(KOFAX_TAG, e.getLocalizedMessage());
} else {
Log.d(KOFAX_TAG, "Image sent...");
}
condition.open();
}
});
Log.d(KOFAX_TAG, "blocking...");
condition.block();
Log.d(KOFAX_TAG, "continuing...");
return null;
}
}