我想将进度对话框与 asynctask 一起使用。我试过了,但它在收到响应后向我显示了对话框。这是我的调用函数..到 asycnk 任务正如我所料,我面临的问题是因为这个AppResponse = reqClient.execute().get(); 因为我也必须从这个异步任务中获取返回值。所以请参阅这两个文件以供参考
void postHttpRequest(String userId,String pass,TextView error){
RequestClient reqClient = new RequestClient(IweenTravelLoginPage.this);
String AppResponse = null;
try {
url = "";
Log.d("Http Post URL is ", url);
AppResponse = reqClient.execute().get();
String status = ValidateLoginStatus.checkLoginStatus(AppResponse);
Log.d("Status recived", status);
if(status.equals("200")){
saveInformation(userId,pass);
startingActivity();
}else{
error.setText("Incorrect UserName or Password");
}
} catch (Exception e) {
Log.e("Exception Occured", "Exception is "+e.getMessage());
}
该函数用于发送请求
public class RequestClient extends AsyncTask<String, Void, String>{
Context context;
public RequestClient(Context c) {
context = c;
}
@Override
protected void onPreExecute() {
super.onPreExecute();
}
@Override
protected String doInBackground(String... aurl){
String responseString="";
HttpClient client = null;
try {
client = new DefaultHttpClient();
HttpGet get = new HttpGet(IweenTravelLoginPage.url);
HttpResponse responseGet = client.execute(get);
HttpEntity resEntityGet = responseGet.getEntity();
if (resEntityGet != null) {
responseString = EntityUtils.toString(resEntityGet);
Log.i("GET RESPONSE", responseString.trim());
}
} catch (Exception e) {
Log.d("ANDRO_ASYNC_ERROR", "Error is "+e.toString());
}
Log.d("ANDRO_ASYNC_RESPONSE", responseString.trim());
client.getConnectionManager().shutdown();
return responseString.trim();
}
@Override
protected void onPostExecute(String response) {
super.onPostExecute(response);
}
}
所以请建议我如何显示进程对话框。我尝试了stackoverflow上的所有示例。但是所有这些都不适合我。请帮助