progress dialog is not displaying in async task when asynctask is called from separate class

前端 未结 5 703
小蘑菇
小蘑菇 2021-01-23 06:54

I have posted a question Progress Dialog is not displaying while getting data from separate thread class but I haven\'t got the appropriate answers. I have already used async t

5条回答
  •  自闭症患者
    2021-01-23 07:49

    you dont need to start a background method for postExecute. as @baske wrote, you have problem with .get() - that is blocking your thread even if your are using AsyncTask. try someting related to the linked question, so only add your YourActivityClass as a param to the construdtor of JsonData

    public JsonData(YourActivityClass activity) 
    {
        this.activity=activity;
        mProgressDialog = new ProgressDialog(activity);
    
    }
    protected void onPostExecute(String jsondata) {
        if (mProgressDialog != null || mProgressDialog.isShowing()){
            mProgressDialog.dismiss();
        }
        if(jsondata!=null) {
            activity.yourcallback(jsondata)
        }
    
    }
    

    And define the yourcallback() in YourActivityClass

    private void yourcallback(String data) {
        jsonRecordsData=data;
        showRecordsFromJson();
    
    }
    

提交回复
热议问题