PendingIntent.getBroadcast lint warning

Viewed 1249

There is this new warning about using PendingIntent.getBroadcast as a notification's content intent:

builder.setContentIntent(PendingIntent.getBroadcast(FirebaseNotification.this, newID,
                                                  new Intent(getString(R.string.notif_broadcast))
                                                          .setClass(FirebaseNotification.this, NotificationActions.class)
                                                          .putExtra(getString(R.string.thumbnail), bitmap);

Lint message:

Notifications should only launch a BroadcastReceiver from notification actions (addAction)

Notifications should only launch a BroadcastReceiver from notification actions (addAction) (This BroadcastReceiver intent is launched from a notification; this is discouraged except as notification actions)

I do not see this anywhere yet in the documentation, so why is this now discouraged? Is it for user experience and to provide clear context of what the notification can do?

1 Answers

It wouldn't make much sense to a user if tapping a notification sent a broadcast. The expected behaviour would be to open the actual app that sent the notification originally, so I am not sure that sending another notification (which I presume is what your code achieves) would be good UX.

They do actually mention this is the material design documentation where they say:

When the user taps a notification, they should be taken to a screen in your app that relates directly to that notification and lets them take immediate action.

Related