Section1
Notification notification1 = builder .setContentTitle(mText) .setContentText(mText) .setContentIntent(PendingIntent.getActivity(this,1,intentTest,0)) .setSmallIcon(R.drawable.ic_launcher) .setTicker("haha") .setOngoing(true) .setPriority(NotificationCompat.PRIORITY_MAX) .setWhen(System.currentTimeMillis()) .build();
manager.notify(1, notification1);
上面的代码,即便多次执行,最后点击获取到的intent,还是第一个intent
Section2
修改上面的代码
NotificationCompat.Builder builder = new NotificationCompat.Builder(this); RemoteViews remoteViews = new RemoteViews(getPackageName(), R.layout.user_define_notification_style_multi_news); Intent intentTest = new Intent(this,Test.class); intentTest.putExtra("url","http://sina.com.cn"); Notification notification1 = builder .setContentIntent(PendingIntent.getActivity(this,(int)System.currentTimeMillis(),intentTest,0)) .setSmallIcon(R.drawable.ic_launcher) .setTicker("haha") .setOngoing(true) .setPriority(NotificationCompat.PRIORITY_MAX) .setWhen(System.currentTimeMillis()) .build(); notification1.bigContentView = remoteViews; manager.notify(1, notification1);
这个时候后面的执行终于可以覆盖前面的Intent了。
Section3
那么notify后面的第一个参数是做什么用的?
经测试,notify之后通知栏多了一个notification
========================================================
结论:
1.
PendingIntent.getActivity 的requestCode 用来区分是不是同一个Intent
2.
manager.notify 的第一个参数用来区分是否是通知栏的同一个notification