Visit Sponsor

Written by 4:15 pm Android

Progress Notification in Android Example and Implementation

Overview

Progress notifications inform users about ongoing background tasks such as file downloads, uploads, installations, or data processing. Android’s notification system enables apps to display progress indicators within the notification UI, helping users understand task status without holding the app in the foreground.

This document explains how to implement progress notifications in Android using the Notification APIs and provides code examples for both determinate and indeterminate progress scenarios.

Notification Basics in Android

Android notifications are delivered through the NotificationManager and are represented by Notification objects. Since Android 8.0 (API level 26), notifications also require a Notification Channel to ensure consistent presentation and user control.

Notification Key Concepts

  • Notification Channel: Required for API level 26 and above; groups related notifications
  • Notification ID: Uniquely identifies each notification instance
  • Notification Manager: System service responsible for showing notifications

Setting Up a Notification Channel

Before posting notifications on Android 8.0+, you must create a channel.

NotificationManager notificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    NotificationChannel channel = new NotificationChannel(
            "progress_channel",
            "Progress Notifications",
            NotificationManager.IMPORTANCE_LOW
    );
    channel.setDescription("Shows ongoing task progress");
    notificationManager.createNotificationChannel(channel);
}

This channel groups progress notifications and allows users to manage their preferences.

Determinate Progress Notification

Determinate progress notifications show a percentage or portion of total work completed. These are used when the task’s total size is known (for example, 0–100% of a download).

Step-by-Step Example

  1. Build a notification with a progress bar
  2. Update progress periodically
  3. Notify the system to refresh the UI
NotificationManager notificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "progress_channel")
        .setSmallIcon(R.drawable.ic_download)
        .setContentTitle("Downloading file")
        .setContentText("Download in progress...")
        .setPriority(NotificationCompat.PRIORITY_LOW)
        .setOnlyAlertOnce(true);

final int NOTIFICATION_ID = 1001;
int progressMax = 100;

builder.setProgress(progressMax, 0, false);
notificationManager.notify(NOTIFICATION_ID, builder.build());

// Simulate progress update
new Thread(() -> {
    for (int progress = 1; progress <= progressMax; progress++) {
        builder.setProgress(progressMax, progress, false);
        notificationManager.notify(NOTIFICATION_ID, builder.build());
        try {
            Thread.sleep(50);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
    builder.setContentText("Download complete")
           .setProgress(0, 0, false);
    notificationManager.notify(NOTIFICATION_ID, builder.build());
}).start();

In this example:

  • setProgress(max, current, false) shows a determinate progress bar
  • setOnlyAlertOnce(true) prevents repeated notification sounds

Indeterminate Progress Notification

Indeterminate notifications are used when the duration or size of the task is unknown (for example, waiting for a network response). They show a looping animation instead of a numeric percentage.

NotificationCompat.Builder builder = new NotificationCompat.Builder(this, "progress_channel")
        .setSmallIcon(R.drawable.ic_sync)
        .setContentTitle("Syncing data")
        .setContentText("Please wait")
        .setPriority(NotificationCompat.PRIORITY_LOW)
        .setProgress(0, 0, true);

NotificationManager notificationManager =
        (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

notificationManager.notify(1002, builder.build());

Here:

  • The third flag in setProgress() (true) indicates an indeterminate progress mode

Updating and Clearing Notifications

Once the background task completes, update the content and optionally remove the progress bar.

builder.setContentText("Operation completed")
       .setProgress(0, 0, false);

notificationManager.notify(NOTIFICATION_ID, builder.build());

To remove the notification entirely:

notificationManager.cancel(NOTIFICATION_ID);

Best Practices

Use Priority Wisely

  • Progress notifications tend to be low priority to avoid interrupting users unnecessarily
  • Reserve high priority for time-sensitive alerts

Minimize Frequency of UI Updates

Updating notifications too frequently can hurt performance. Batch progress updates at reasonable intervals.

Provide Clear Completion Feedback

When a task completes, update the text and remove the progress bar to avoid stale indicators.

Visited 6 times, 4 visit(s) today
Close