Android ProggersDialog不会在asynctask中显示

Android ProggersDialog不会在asynctask中显示,android,android-asynctask,progressdialog,Android,Android Asynctask,Progressdialog,我的代码将在AsyncTask中从web获取jsonString,然后将该字符串auth2返回给MainActivity 我有一个问题,progressDialog无法在AsyncTask中显示 我的任务代码: /** * Async task class to get json by making HTTP call * */ private class GetContacts extends AsyncTask<String, String, String> {

我的代码将在AsyncTask中从web获取jsonString,然后将该字符串auth2返回给MainActivity

我有一个问题,progressDialog无法在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等方法有关?

onProgressUpdate用于更新UI上的进度。它接受一个与AsyncTask类定义中的第二个参数相对应的参数。可以通过调用publishProgress从doInBackground方法的主体中触发此回调


有关详细信息,请检查link和link。

为什么调用super.onPreExecute?如何调用'GetContacts'AsyncTask我将主机传递给apiHost,并使用以下方法进行调用:String auth2=new GetContacts.ExecuteAbiHost.get;get将阻止UI,因此请尝试使用新的GetContacts.ExecuteAbiHost