What's the best practice in Android about uploading a photo with a downloadable message?

I need to upload a photo to the server and show the uploading message.

I tried with this code, but ProcessDialog is unstable ...

new UploadTask(MainActivity.this).execute(bitmap);
....
private class UploadTask extends AsyncTask<Bitmap, Void, Long> {                       
   private ProgressDialog dialog = null;        
   private Context context;     
   public UploadTask(Context context){
     this.context = context;
   }        
   protected void onPreExecute() {      
        this.dialog = new ProgressDialog(this.context);
        this.dialog.setMessage("Loading...");
        this.dialog.setCancelable(false);           
        this.dialog.show();         
   }

 protected void onPostExecute(Long result) {                    
    if(this.dialog != null){
        this.dialog.dismiss();
    }
}

      

+3


source to share


1 answer


The best way to do this is to implement an IntentService and report the broadcast status. please fill in full code from github

An Android library that provides an easy-to-use file download service with Android Action Center integration



https://github.com/alexbbb/android-upload-service

let me know if you face any problem to integrate this code

+4


source







All Articles