Android Progress Notification with Examples

In android, Progress Notification is used to show the progress of an ongoing operation in the notification bar. By using progress notification, we can easily know how much percentage of the current operation completed and how long the operation will run to complete the remaining operation.


In android, two types of progress indicators available, one is determinate and another one is indeterminate. If we are known about how long the operation will take to complete, then we can use the determinate form of the indicator. In case if we are not aware of how long the operation will run then we can use the indeterminate form of indicator.


Following is the pictorial representation of using a different type of android progress indicators (determinate and indeterminate) to show the progress of current operation in notification.


Android Progress Notification in Determinate and Indeterminate Modes


Generally, the progress indicators in android are implemented by using the ProgressBar class. To display the progress indicators in our app, we need to add the progress bar to our notification by calling setProgress(max, progress, false) method and then issue the notification.


Here the third argument in setProgress() method is used to indicate whether the progress bar is determinate (false) or indeterminate (true). As our operation proceeds, we need to increase the value of progress and update the status of notification. At the end of operation, the progress value must be equal to max value. The better way to call setProgress() is to set max value to 100 and then increment progress as a percent complete value for the operation.


Once the operation is done leave the progress bar showing or remove it by calling setProgress(0,0, false) and update the notification text to show that the operation is complete.


Now we will see how to create and show the progress bar in an android notification bar with examples.

Android Progress Notification Example

Create a new android application using android studio and give names as ProgressNotification. In case if you are not aware of creating an app in android studio check this article Android Hello World App.


Now open an activity_main.xml file from \res\layout path and write the code like as shown below


<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android=""
android:orientation="vertical" >
android:text="Show Notification"
android:layout_marginTop="100dp" android:layout_marginLeft="120dp"/>

If you observe above code we created a one Button control in XML Layout file to show the progress indicator in notification when we click on Button


Once we are done with creation of layout with required controls, we need to load the XML layout resource from our activity onCreate() callback method, for that open main activity file from \java\com.tutlane.progressnotification path and write the code like as shown below.

package com.tutlane.progressnotification;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {
private NotificationManager mNotifyManager;
private NotificationCompat.Builder mBuilder;
int id = 1;
protected void onCreate(Bundle savedInstanceState) {
        Button b1 = (Button) findViewById(
new View.OnClickListener() {
public void onClick(View v) {
mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder = new NotificationCompat.Builder(MainActivity.this);
mBuilder.setContentTitle("File Download")
"Download in progress")
// Start a the operation in a background thread
new Thread(
new Runnable() {
public void run() {
int incr;
// Do the "lengthy" operation 20 times
for (incr = 0; incr <= 100; incr+=5) {
// Sets the progress indicator to a max value, the current completion percentage and "determinate" state
mBuilder.setProgress(100, incr, false);
// Displays the progress bar for the first time.
// Sleeps the thread, simulating an operation
try {
// Sleep for 1 second
catch (InterruptedException e) {
"TAG", "sleep failure");
// When the loop is finished, updates the notification
mBuilder.setContentText("Download completed")
// Removes the progress bar
// Starts the thread by calling the run() method in its Runnable

If you observe above code we are created a progress notification using setProgress() method and showing the progress notification on Button click.


Generally, during the launch of our activity, the onCreate() callback method will be called by the android framework to get the required layout for an activity.

Output of Android Progress Notification Example

When we run the above example using android virtual device (AVD) we will get a result like as shown below.


Android Progress Notification Example Result


If you observe above result we created a progress notification and shown it on Button click based on our requirements.


This is how we can use progress notification in our android applications based on our requirements.