Android:保持通知激活



在我正在做的这个项目中,有一堆警报被创建,当它们响起时,这就是我目前正在发生的事情。

  1. 报警响

  2. 通知放在状态栏

  3. 当用户选择通知时,它会将他们带到应用程序中的特定Activity来处理当前活动的通知

  4. 只要有未处理的通知,通知就停留在状态栏

现在的问题是,当用户从通知中心选择警报时,它停留在那里,但它变成'死',如果用户离开应用程序,然后再次点击通知,它不会带用户回到应用程序,这就是LogCat所说的…

StatusBar - Sending contentIntent failed: android.app.PendingIntent$CanceledException
InputManagerService - Window already focused, ignoring focus gain of: com.android.internal.view.IInputMethodClient$Stub$Proxy@44f94258

我想出了一个解决这个问题的办法…还有人处理过这个问题吗?

答案:requestCode和Notification ID必须匹配,参见下面我对iAlertUniqueID的使用:

notification.contentIntent = PendingIntent.getActivity(context, iAlertUniqueID, targetActivityIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
notificationMgr.notify(iAlertUniqueID++, notification);

iAlertUniqueID只是一个静态int(不是final!)在我的类扩展BroadcastReceiver

最新更新