[英]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.