我对锁定有点生疏,我正在尝试在我的 android 应用程序上进行简单的网络通信。不用说,你必须AsyncTask
在android中使用来做这些通信。如何锁定主线程直到AsyncTask
完成?
public int read(){
ReadTCPTask t = new ReadTCPTask();
boolean canGoOn = false;
// We can proceed once we acquire the lock?
while (!canGoOn)
canGoOn = lock.tryLock();
t.execute();
// something that will wait here until the asynctask is done?
return readSize;
}