[Android] Curious issue about notifications

It may seem obvious, but this issue annoyed me very much and made me waste some valious hours.

As scenario, imagine that you launch ActivityA, and after clicking a button, you launch ActivityB on top of it.

Now, ActivityB executes a long-time background operation (such as parsing a JSON file), and we want a Notification to tell us the progress.

The author of the Notification could be ActivityA, so we can keep on using the App, and even click “back”, and we will still be informed about the progress of our operation.

Well, just one detail when doing that: Don’t forget to set the Notification’s Small Icon, or else it won’t show up (It will if we launch it from ActivityB without smallIcon, but in case of ActivityA, it won’t). Here is some code:

Intent i = getIntent();
int notificationId = 100;
PendingIntent pi = PendingIntent.getActivity(ActivityA.this, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
.setContentText("10% parsed")
.setProgress(100, 10, false)
.setSmallIcon(R.drawable.icon); // Do not forget this line!!
mNotifyManager.notify(notificationId, mNotificationBuilder.build());

I know it is quite silly, but remember it! 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s