2

次のコードは、通知を表示して int データを送信しますが、他のアクティビティでgetExtras()null. なんで?

int notificationID = 1;
NotificationManager nm = (NotificationManager) getSystemService(getApplicationContext().NOTIFICATION_SERVICE);


Intent i = new Intent(getApplicationContext(), DownlodResult.class);
i.putExtra("notificationID", 1);


PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, i, 0);


CharSequence tickerText = "There are updates !";
long when = System.currentTimeMillis();
int icon = R.drawable.ic_launcher;
Notification notification = new Notification(icon,tickerText,when);
CharSequence contentTitle = "There are updates";
CharSequence contentText = "Please click here to view it";
notification.setLatestEventInfo(getApplicationContext(), contentTitle, contentText, contentIntent);



notification.vibrate = new long[] { 100, 250, 100, 500}; // Needs vibrate permissions
nm.notify(notificationID, notification);
4

1 に答える 1

15

おそらく、PendingIntent は既に存在し、作成されていませんが、再利用されています。PendingIntent.FLAG_UPDATE_CURRENTフラグで作成してみてください:

PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(), 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

https://stackoverflow.com/a/9330144/530804およびその質問に対する他の回答を参照してください。

于 2012-07-13T18:12:40.783 に答える