我想在數據庫中放入一個entry。用的下面的代碼:String url = String.format("http://xxxxxxx/xxx/index.php?home=yes&pid=%s", pid);
// Create a new HttpClient and Post Header
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(url);
try {
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = httpclient.execute(httppost, responseHandler);
Log.e("abc", response);
return response;
} catch (ClientProtocolException es)
{
Log.e("x" , es.getMessage());
return "";
} catch (IOException e)
{
Log.e("aasx" , e.getMessage());
return "";
}這段代碼能正常運行,現在當有網絡連接的時候,代碼就會困在httpclient.execute(httppost, responseHandler); 大約倆分鐘。有什么方法可以實現檢查幾秒鐘后,如果沒有反應的就會就catch the exceptions?
從 android 應用程序響應時間發送 php 查詢到服務器
幕布斯7119047
2019-03-19 17:18:32