我有一个正在运行的服务,当它收到一条消息说它必须更改时,它会更新通知栏中的通知。
但是,当要更新通知时,有时会出现以下错误
java.lang.IllegalArgumentException: contentIntent required
这是我的代码:
变量设置
int icon = R.drawable.notification;
CharSequence tickerText = "Test";
long when = System.currentTimeMillis();
PendingIntent contentIntent;
Notification notification = new Notification(icon, tickerText, when);
NotificationManager mNotificationManager;
NotificationManager 创建
String ns = Context.NOTIFICATION_SERVICE;
mNotificationManager = (NotificationManager) getSystemService(ns);
通知创建
Intent notificationIntent = new Intent(this, TestsApp.class);
contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.flags |= Notification.FLAG_NO_CLEAR;
notification.icon = R.drawable.notification3;
notification.setLatestEventInfo(this, "Registering", "Test", contentIntent);
mNotificationManager.notify(1, notification);
通知更新
notification.icon = R.drawable.notification2;
notification.setLatestEventInfo(getApplicationContext(), "Registered", "Test", contentIntent);
mNotificationManager.notify(1, notification);
所以我的 contentIntent 发生了一些事情,这对吗?
它在我的 Service 类的顶部声明为成员变量,除了上面显示的代码之外,它没有在代码中的任何其他地方使用,那么它在哪里可以重置为 null?