我正在使用 BroadCast Listener 来收听传入的电话统计信息,然后推送这样的通知:
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);
因此,当有多个调用时,我希望有多个调用通知,并且当我单击每个通知时,我希望使用附加参数启动一个 Activity 。但是,我可以看到稍后启动的 Activity 获取了上一个调用的 Intent。
这是我从 Activity 中查看 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));
如何将 Intent 单独称为独立 Activity ?
最佳答案
试试这个:
PendingIntent.getActivity(context, 0 , notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
注意 PendingIntent.getActitity 方法的最后一个参数。 如果您想知道应该使用哪个 FLAG,请参阅 API 文档 - [ http://developer.android.com/reference/android/app/PendingIntent.html#getActivity(android.content.Context , int, android.content.Intent, int)][1]
[1]: http://developer.android.com/reference/android/app/PendingIntent.html#getActivity(android.content.Context , int, android.content.Intent, int)
~海豚~
关于android - 使用 PendingIntent 开始新 Activity 时的混淆行为,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4472447/