关键代码:
1.in.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
保证我所启动的Activity位于栈顶,作用将当前栈顶的Activity移除
2.PendingIntent pi = PendingIntent.getActivity(ReceivedSMSService.this,
id, in, PendingIntent.FLAG_UPDATE_CURRENT);
PendingIntent.FLAG_UPDATE_CURRENT:这个标志位可保证当PendingIntent中包装的Intent的数据改变时,系统给我重新来创建PendingIntent
3.id++;
PendingIntent pi = PendingIntent.getActivity(ReceivedSMSService.this, id, in, PendingIntent.FLAG_UPDATE_CURRENT);
mNotificationManager.notify(id, mNotification);
id这个变量起到了关键性的作用:处理多个通知
程序完整代码: