ProgressBar in asynctask is not showing on upload

后端 未结 2 1429
暖寄归人
暖寄归人 2020-12-06 15:18

Can someone tell me, why progressbar isnt showing when picture is being uploaded. I copied asynctask structure from my old project where it works. In my old project i use as

2条回答
  •  时光说笑
    2020-12-06 15:55

    Run on ui thread in asynctask doinbackground() is not correct. Also you are returning null in doInBackground() and you have parameter file_url in onPostExecute(). Return value in doInbackground() recieve value in onPostExecute().

    doInBackGround() runs in background so you cannot access or update ui here.

    To update ui you can use onPostExecute().

    Your AsyncTask should be something like below. You are doing it the wrong way.

    http://developer.android.com/reference/android/os/AsyncTask.html. See the topic under The 4 steps

     pd= new ProgressDialog(this);
     pd.setTitle("Posting data");
     new PostTask().execute();
    
    private class PostTask extends AsyncTask {
    
    protected void onPreExecute()
    {//display dialog.
      pd.show();
    }
    protected SoapObject doInBackground(Void... params) {
    // TODO Auto-generated method stub
           //post request. do not update ui here. runs in background
    return null;
    }
    
    protected void onPostExecute(Void param)
    {   
    
     pd.dismiss();
     //update ui here
    }
    

提交回复
热议问题