To show progress of a task, we use progress bar. We should use progress dialog if we want the user to wait till the task complete. For example, When we are downloading or uploading something, then we should show progress dialog so that the user get to know that some process is running in the background.
Progress bar can be devided into 2 parts based on there characteristic:
A progress bar can be made indeterminate. In indeterminate mode, the progress bar shows a cyclic animation without an indication of progress. This mode is used by applications when the length of the task is unknown. The indeterminate progress bar can be either a spinning wheel or a horizontal bar.
A progress bar can be made determinate. This mode is used by applications when the length of the task is well known.
In this example, I've tried to show determinate as well as indeterminate progress bar using ProgressDialog and ProgressBar widget.
Step 1: Create a new project in Android Studio and name it Android progress bar.
Step 2:Open res -> drawable -> activity_main.xml and replace the code with code of activity_main.xml with the below given code.activity_main.xml
Step 3: Open MainActivity.java and replace its code with below given code.
Step 4:Clean and run your project to see the result.