开始的PendingIntent新的活动时,混乱的行为 [英] Confusing behavior when starting new activity with PendingIntent
问题描述
我使用的广播听众收听电话传入STAT然后推通知如下:
I am using BroadCast Listener to listen to incoming phone stat then pushing a Notification like this:
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);
所以,当有多个电话,我期望有多个来电通知,当我点击每个通知,我期待与连接的参数开始活动。不过,我可以看到,活动开始后,得到previous调用的意图。
So when there are multiple calls, I expect to have multiple call notification and when I click each notification, I expect to start an activity with the attached parameters. However, I can see that the Activities that starts later, gets the Intent of the previous call.
下面是我如何期待到意图从活动
Here is how I am looking into intent from the Activity
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));
我如何才能让意图分别调用独立的活动?
How can I keep the intents separately call independent activity?
推荐答案
试试这个:
PendingIntent.getActivity(context, 0 , notificationIntent, PendintIntent.FLAG_UPDATE_CURRENT);
注意PendingIntent.getActitity方法的最后一个参数。
如果你想知道你应该使用哪个标志,请参阅API文档 -
[http://developer.android.com/reference/android/app/PendingIntent.html#getActivity(android.content.Context, INT,android.content.Intent,INT)] [1]
Notice the last parameter of the PendingIntent.getActitity method. If you'd like to know which FLAG you should use, see the API documents - [http://developer.android.com/reference/android/app/PendingIntent.html#getActivity(android.content.Context, int, android.content.Intent, int)][1]
[1]:<一href=\"http://developer.android.com/reference/android/app/PendingIntent.html#getActivity(android.content.Context\" rel=\"nofollow\">http://developer.android.com/reference/android/app/PendingIntent.html#getActivity(android.content.Context, INT,android.content.Intent,INT)
[1]: http://developer.android.com/reference/android/app/PendingIntent.html#getActivity(android.content.Context, int, android.content.Intent, int)
〜多尔夫〜
这篇关于开始的PendingIntent新的活动时,混乱的行为的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!