繁体   English   中英

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

[英]Notification disappearing randomly without cancelling them

我的程序通知随机消失。 有时几秒钟后,有时我什至看不到它们,有时又保留它们,直到我手动取消它们(这是我想要的行为)。

我的通知是由Service启动的,该服务由JobService定期调用。 在StartService中调用以下函数。 多亏了振动,我可以说函数被调用了。 但是我不明白为什么通知会消失。 我没有取消通知(也没有cancelAll)。 我认为可能是因为我的服务终止了,但这是服务的正常循环,当我确实希望通知停留在屏幕上时...

谢谢你的帮助!

// 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);

}

好吧,我通过作业服务启动的服务调用了通知。 我改变了这一点:通知现在由jobservice启动。 我没有问题了。

暂无
暂无

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

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