変更する必要があるというメッセージを受け取ったときに、通知バーの通知を更新するサービスを実行しています。
ただし、通知を更新するときに次のエラーが発生することがあります
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 にリセットされるのでしょうか?