Lucas Mendonca
Lucas Mendonca

Reputation: 436

When making a Notification non-dismissable, what's the difference between using each of these solutions?

I want to make an Android Notification non-swipable so the user can only tap on it, but can't dismiss it.

So far I've found these two solutions:

  1. Setting Notification Builder .setOngoing(true)
  2. Adding flag Notification.FLAG_NO_CLEAR to Notification object

Upvotes: 1

Views: 1110

Answers (2)

matdev
matdev

Reputation: 4283

Both solutions make the notification non-dismissable, but calling .setOngoing(true) makes the notification an ongoing notification, by setting its flag to Notification.FLAG_ONGOING_EVENT.

With the flag Notification.FLAG_NO_CLEAR, the notification stays a regular one.

Ongoing notifications differ from regular notifications in the following ways:

Ongoing notifications are sorted above the regular notifications in the notification panel

Ongoing notifications do not have an 'X' close button, and are not affected by the "Clear all" button.

Upvotes: 3

Squti
Squti

Reputation: 4487

They are very similar. FLAG_NO_CLEAR is using when the notification should not be canceled when the user clicks the Clear all button. setOngoing also change Notification.FLAG_ONGOING_EVENT which has the same behavior but according to the doc Ongoing notifications do not have an 'X' close button and when you engage your notification with a service, The service could control your notification dismissable.

Upvotes: 1

Related Questions