0
等待future.isDone()== true返回调用线程(main)的标准方法是什么?返回可调用结果的非阻塞方法
我试着通过一个asyncMethod()在调用线程(主线程)上返回一个结果。 asyncMethod()立即返回,但在返回之前,首先触发一个导致广播意图回到主线程的进程。在主线程中,我检查future.isDone(),但不幸的是,future.isDone()仅在一半时间返回true。
ExecutorService pool = Executors.newSingleThreadExecutor();
Callable<Boolean> callable = new Callable<Boolean>(){
public Boolean call() {
Boolean result = doSomething();
callbackAsync(); //calls an async method that returns immediately, but will trigger a broadcast intent back to main thread
return result;
}
};
new broadCastReceiver() { ///back on main thread
...
case ACTION_CALLABLE_COMPLETE:
if (future.isDone()) // not always true...
future.get();
}