简体   繁体   English

通知会随机消失而不会取消

[英]Notification disappearing randomly without cancelling them

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. 我的通知是由Service启动的,该服务由JobService定期调用。 The following function is called in StartService. 在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). 我没有取消通知(也没有cancelAll)。 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. 我改变了这一点:通知现在由jobservice启动。 I do not have the problem anymore. 我没有问题了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM