1

我正在开发在开始获取一些基本数据后立即使用 Web 服务的应用程序。当我进行新模拟器的“全新安装”时,应用程序崩溃,因为 Web 服务消耗超时。但是,当我立即运行相同的代码和相同的模拟器时,它工作正常,然后每次都可以,只是在“干净”模拟器上的第一次运行有问题。任何建议,想法为什么?

PS:使用 .net webservice 在 android 上返回 xml 和 ksoap2 来使用它。

谢谢

4

1 回答 1

0

I am sure you need to setConnectionTimeout and setSoTimeout while making web request.

For example:

HttpGet httpGet = new HttpGet(url);
HttpParams httpParameters = new BasicHttpParams();

// Set the timeout in milliseconds until a connection is established.
int timeoutConnection = 3000;
HttpConnectionParams.setConnectionTimeout(httpParameters, timeoutConnection);

// Set the default socket timeout (SO_TIMEOUT) 
// in milliseconds which is the timeout for waiting for data.
int timeoutSocket = 5000;
HttpConnectionParams.setSoTimeout(httpParameters, timeoutSocket);

DefaultHttpClient httpClient = new DefaultHttpClient(httpParameters);
HttpResponse response = httpClient.execute(httpGet);
于 2011-11-08T10:13:55.690 回答