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);
.setProgress(100, 10, false)
.setSmallIcon(R.drawable.icon); // Do not forget this line!!
I know it is quite silly, but remember it! 🙂