Md Ayon Rahman
Md Ayon Rahman

Reputation: 11

Firebase RecyclerView

how can i set progress dialog in this code:

class RetrievePdfView  extends AsyncTask<String,Void,InputStream> {

    @Override
    protected InputStream doInBackground(String... strings) {
       InputStream inputStream=null;
       try{

           URL url=new URL(strings[0]);
           HttpURLConnection urlConnection=(HttpURLConnection)url.openConnection();
           if(urlConnection.getResponseCode()==200)
           {
               inputStream=new BufferedInputStream(urlConnection.getInputStream());
           }
       }
       catch (IOException e)
       {
           return null;
       }
       return inputStream;
    }

    @Override
    protected void onPostExecute(InputStream inputStream) {
        super.onPostExecute(inputStream);
        pdfView.fromStream(inputStream).load();
    }

Upvotes: 1

Views: 37

Answers (1)

Ali
Ali

Reputation: 9994

You need to add following code to your implementation. You need to pass Activity as a parameter in the AsyncTask constructor :

/** progress dialog to show user that the background task is processing. */
    private ProgressDialog dialog;

    public RetrievePdfView(Activity activity) {
        dialog = new ProgressDialog(activity);
    }

   @Override
   protected void onPreExecute() {
       this.dialog.setMessage("Progress start");
       this.dialog.show();
   }

    @Override
    protected void onPostExecute(final Boolean success) {
       if (dialog.isShowing()) {
           dialog.dismiss();
       }
    }

In order to call this AsyncTask you need call it like this in your Activity :

RetrievePdfView task = new RetrievePdfView(this);
task.execute(inputStreamString);

Upvotes: 1

Related Questions