Loading Image using picasso inside AsyncTask

后端 未结 3 1623
情话喂你
情话喂你 2020-12-20 10:02

I\'m using picasso to load an image as a background for my activity, I want to use an AsyncTask, while the image is loading, when done the progress bar dismisses to give bet

3条回答
  •  长情又很酷
    2020-12-20 10:09

    You get error because picasso's load function is already async. So you can do this in UI thread like:

    public void functionCalledFromUIThread(){
    
    mProgressDialog = new ProgressDialog(MainActivity.this);
    mProgressDialog.setMessage("Chargement...");
    mProgressDialog.setIndeterminate(false);
    mProgressDialog.show();
    Picasso.with(MainActivity.this).load("http://tv2.orangeadd.com/mediacenter-data/ofc__bg_home.jpg").into(background,new com.squareup.picasso.Callback() {
                 @Override
                 public void onSuccess() {
                    mProgressDialog.dismiss();
                 }
    
                 @Override
                 public void onError() {
                    mProgressDialog.dismiss();
                 }
             }); 
    }
    

提交回复
热议问题