The notification of my program disappear randomly. Sometimes after few seconds, sometimes I cannot even see them, some other times they remains until I cancel them manually (which is the behaviour I want).
My notifications are launched by a Service, which is called regularly by a JobService. The following function is called in StartService. Thanks to the vibrating, I can say the function is called. But I do not understand why the notification disappear. I did not cancel the notification (no cancelAll either). I think it may be because my service die, but it's the normal cycle of a service, when I do want the notification to stay at screen...
Thanks for your help!
// create notification
private void SendDummyNotification() {
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, ActivityParam.class), FLAG_UPDATE_CURRENT);
Notification notification;
notification = new Notification.Builder(this)
.setContentTitle("test notification")
.setContentText("dummy")
.setSmallIcon(R.drawable.notification)
.setWhen(System.currentTimeMillis())
.setShowWhen(true)
.setContentIntent(pendingIntent)
.setPriority(Notification.PRIORITY_LOW)
.build();
// add notification
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(1998, notification);
// vibrate
Vibrator t_vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);
t_vibrator.vibrate(2000);
}
Well, I called the notification through a service started by a jobservice. I changed that: the notification is now launched by the jobservice. I do not have the problem anymore.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.