private String getHttpResponse(String lName,String consultancyArea,String fName,String hospitalName,String date,String time){
String names="a";
System.out.println("iside httprespons");
HttpParams httpParams=new BasicHttpParams();
HttpConnectionParams.setConnectionTimeout(httpParams, 30000);
HttpConnectionParams.setSoTimeout(httpParams,30000);
HttpClient httpClient=new DefaultHttpClient(httpParams);
HttpPost httpPost=new HttpPost("url");
try{
List<NameValuePair> nameValuePairs=new ArrayList<NameValuePair>(6);
nameValuePairs.add(new BasicNameValuePair("LName", lName));
nameValuePairs.add(new BasicNameValuePair("ConsultancyArea", consultancyArea));
nameValuePairs.add(new BasicNameValuePair("fName", fName));
nameValuePairs.add(new BasicNameValuePair("hospitalName",hospitalName));
nameValuePairs.add(new BasicNameValuePair("date", date));
nameValuePairs.add(new BasicNameValuePair("time", time));
httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
HttpResponse httpResponse=httpClient.execute(httpPost);
String result=inputStreamToString(httpResponse.getEntity().getContent()).toString();
JSONObject jasonObejct=new JSONObject(result);
String name1 = jasonObejct.getString("myData");
names=name1;
}catch (JSONException e) {
System.out.println("network error ocured1");
e.printStackTrace();
}catch(ConnectTimeoutException e){
System.out.println("network error ocured2");
}
catch(java.net.SocketTimeoutException e){
System.out.println("network error ocured2");
e.printStackTrace();
}
catch (ClientProtocolException e) {
System.out.println("network error ocured2");
e.printStackTrace();
System.out.println("network error ocured");
}
catch (IOException e) {
System.out.println("network error ocured3");
e.printStackTrace();
}
return names;
}
我正在开发一个 android 应用程序来从远程服务器获取数据。如果服务器没有响应,我想在活动管理器冻结活动之前使连接超时并结束进程。我需要的是一种在 android 活动管理器冻结活动之前结束进程的方法,以防服务器出现故障。