我正在使用广播监听器来监听手机状态,然后推送通知,代码如下:
CharSequence contentTitle = "Contact: " + number;
CharSequence contentText = "Call From: " + number;
Intent notificationIntent = new Intent(context, CallHandler.class);
notificationIntent.putExtra(KEYS.NUMBER, number);
notificationIntent.putExtra(KEYS.STATE, stat);
notificationIntent.putExtra(KEYS.NAME, name);
notificationIntent.putExtra(KEYS.DURATION, duration);
notificationIntent.putExtra(KEYS.START_TIME, startTime);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notif.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notif.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify((int) System.currentTimeMillis(), notif);
所以当有多个调用时,我期望有多个调用通知,并且当我点击每个通知时,我期望启动一个带有附加参数的活动。但是,我发现后面启动的活动会获得先前调用的 Intent。
以下是我从活动中查看意图的方式:
Bundle extras = getIntent().getExtras();
String number = extras.getString(KEYS.NUMBER);
// String state = extras.getString(KEYS.STATE);
long duration = extras.getLong(KEYS.DURATION);
Date start = getStartDate();
((TextView) findViewById(R.id.subject)).setText("");
((TextView) findViewById(R.id.start_time)).setText(tf.format(start));
((TextView) findViewById(R.id.end_time)).setText(tf
.format(getEndDate()));
((TextView) findViewById(R.id.caller_number)).setText(number);
((TextView) findViewById(R.id.notes)).setText(getNotesDefaultContent(
number, duration, start));
如何保持意图分开调用独立的活动?