I am developing an application with a service which show the progress of a timer in the notification area (with a progress bar and a text). I have extracted below a simpler
I had a similar problem. I had a Service
that presented a Notification
with a progress bar that corresponded to a file download. The app would crash with a OutOfMemoryError
, around ten seconds after the user clicked the Notification
bringing them to the app.
I found that adding .setOngoing(true);
to the Builder fixed this problem.
public NotificationCompat.Builder setOngoing (boolean ongoing)
Set whether this is an ongoing notification. 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.
Example:
NotificationCompat.Builder builder = new NotificationCompat.Builder(context).setAutoCancel(true)
.setDefaults(Notification.DEFAULT_ALL)
.setContentTitle("Downloading").setContentText("Download in progress...)
.setSmallIcon(android.R.drawable.stat_sys_download)
.setSound(null)
.setDefaults(0)
.setOngoing(true);