我在客户端的 AsyncTask 中收到 Android 服务器的响应。
问题是,如何强制客户端等待服务器响应?共振有时服务器可能需要几分钟才能响应。
更具体地说,如何检测 socket.getInputStream.read() 是否不包含任何内容,并强制客户端进入等待循环?
最佳答案
我编写了这样的代码
boolean status;
// isURLReachable is the method to check server is available or not
status = isURLReachable(context);
if (status == true) {
h.post(new Runnable() {
@Override
public void run() {
checkLoginDialogue
.setTitle("Authenticating User");
}
});
handlerForLogin.sendMessage(handlerForLogin
.obtainMessage());
} else {
h.post(new Runnable() {
@Override
public void run() {
if (checkLoginDialogue.isShowing()) {
checkLoginDialogue.dismiss();
}
}
});
System.out.println("status IS " + status);
handler.sendMessage(handler.obtainMessage());
}
希望这有帮助
关于Android:WAITING服务器响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19423413/