Search code examples
androidandroid-asynctaskprogressdialogandroid-progressbar

How to create Progress Dialog in Android Application?


I am developing the application to receive some data from the internet while receiving the data I want to show the "Progress Dialog". I used "AsyncTask" in my application.

The question is how to use it and how to show the percentage like 100%?

Please suggest me and give me some example. Thank you and Sorry for my English.


Solution

  • To show the prgress dialog you can use the below code

     ProgressDialog dialog = new ProgressDialog(MainActivity.this);
                    dialog.setMessage("Your message..");
                    dialog.show();
    

    before you call the async task i.e. before new YourTask.execute().

    and in the onPostExecute function of the asynctask You can use

     dialog.dismiss();
    

    to dismiss the dialog.