showing a progress bar during file upload

后端 未结 5 1251
心在旅途
心在旅途 2021-01-21 03:47

I\'ve got an async task that is supposed to show progress during a file upload. Everything is working except that it looks like it finishes the file upload really really fast,

5条回答
  •  悲&欢浪女
    2021-01-21 03:55

    You can try using a AsyncTask ...

    create a progress dialog in onPreExecute method and dismiss the dialog in onPostExecute method..

    Keep the upload method in doInBackground()

    example :

    public class ProgressTask extends AsyncTask {
    
        public ProgressTask(ListActivity activity) {
            this.activity = activity;
            dialog = new ProgressDialog(context);
        }
    
        /** progress dialog to show user that the backup is processing. */
        private ProgressDialog dialog;
    
        protected void onPreExecute() {
            this.dialog.setMessage("Progress start");
            this.dialog.show();
        }
    
            @Override
        protected void onPostExecute(final Boolean success) {
            if (dialog.isShowing()) {
                dialog.dismiss();
            }           
        }
    
        protected Boolean doInBackground(final String... args) {
    

    // your upload code

              return true;
           }
        }
    }
    

提交回复
热议问题