我无法搞清楚Intent,PendingIntent过滤器和标志的通知.
通知正在工作,并且正在按原样生成,但问题是只有最后创建的通知才能保留Bundle Data.
我希望所有通知都保留每个通知的Bundle Data,直到用户点击它们为止.
考虑一个应用程序片刻,当不同的用户向您发送消息时,会创建新通知,当您单击任何通知时,应用程序将启动并带您进入某些特定的活动.我想要相同的东西,但是当有多个通知时,最后一个通知会将Data保留在上一个通知中,而其中包含Bundle Data和Intent.
每次点击通知时,还有一个过滤器用于限制应用程序启动MainActivity的新实例.
每个通知的Notification_ID都不同.
public class AlarmSchedulingService extends IntentService {
private NotificationManager mNotificationManager;
public AlarmSchedulingService() {
super("SchedulingService");
}
protected void onHandleIntent(Intent intent) {
Bundle extras = intent.getExtras();
sendNotification(extras.getInt(KEY_EXTRAS_NOTIFICATION_ID));
}
public void sendNotification(int NOTIFICATION_ID) {
mNotificationManager = (NotificationManager) this
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = new Intent(this,MainActivity.class);
intent.putExtra(keyName,extraData);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(this,intent,PendingIntent.FLAG_UPDATE_CURRENT);
// use the right class it should be called from the where alarms are set
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
this)
.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(titleString)
.setStyle(
new NotificationCompat.BigTextStyle()
.bigText(messageString))
.setDefaults(
Notification.DEFAULT_SOUND
| Notification.DEFAULT_LIGHTS)
.setContentText(messageString);
mBuilder.setContentIntent(contentIntent);
mNotificationManager.notify(NOTIFICATION_ID,mBuilder.build());
}
}