【发布时间】:2016-05-02 15:23:33
【问题描述】:
我正在尝试在套接字建立连接时显示“等待”对话框。你知道为什么这段代码不起作用吗?
onProgressUpdate 在 doInBackground 结束时被调用。我打算在 connectionSocket.connect 超时之前显示它。
以下位
dialog = connection.dialog("progress");
dialog.show();
单独使用效果很好!
@Override
protected Boolean doInBackground(String... ip) {
Log.i("CONNECTION","doInBackground : Creating socket");
Boolean result = false;
try {
publishProgress();
connectionSocket = new Socket();
connectionSocket.connect(new InetSocketAddress(ip[0], connection.getServerPort()), 5000);
publishProgress();
Log.i("CONNECTION","doInBackground : Socket created");
result = true;
} catch (UnknownHostException e) {
Log.i("CONNECTION","doInBackground : Error creating socket. UnknownHostException");
} catch (IOException ioe) {
Log.i("CONNECTION","doInBackground : Error creating socket. IOException");
}
return result;
}
@Override
protected void onProgressUpdate(Void... values) {
super.onProgressUpdate(values);
Log.i("CONNECTION","onProgressUpdate");
dialog = connection.dialog("progress");
dialog.show();
}
感谢您的帮助:*
【问题讨论】:
标签: android sockets android-asynctask