我的代码将在AsyncTask中从web获取jsonString,然后将此字符串(auth2)返回给MainActivity。
我遇到progressDialog不会在AsyncTask中显示的问题。
我的AsyncTask代码:
/**
* Async task class to get json by making HTTP call
* */
private class GetContacts extends AsyncTask<String, String, String> {
@Override
protected void onPreExecute() {
super.onPreExecute();
// Showing progress dialog
pDialog = new ProgressDialog(MyActivity.this);
pDialog.setMessage("Please wait...");
pDialog.setCancelable(false);
pDialog.show();
}
@Override
protected String doInBackground(String... params) {
// Creating service handler class instance
ServiceHandler sh = new ServiceHandler();
//pass url string
String url = params[0];
// Making a request to url and getting response
String jsonStr = sh.makeServiceCall(url, ServiceHandler.POST);
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
JSONObject jsonUserInfo=jsonObj.getJSONObject("user_info");
String auth2 = jsonUserInfo.getString("auth");
return auth2;
} catch (JSONException e) {
e.printStackTrace();
}
} else {
Log.e("ServiceHandler", "Couldn't get any data from the url");
}
return null;
}
@Override
protected void onPostExecute(String auth2) {
super.onPostExecute(auth2);
// Dismiss the progress dialog
if (pDialog.isShowing()){
pDialog.dismiss();
}
}
}
可能有什么问题?它与方法void,string等有关吗?