我正在使用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);
因此,当有多个呼叫时,我希望有多个呼叫通知,当我单击每个通知时,我希望启动带有附加参数的活动.但是,我可以看到稍后启动的活动获取上一次调用的Intent.
以下是我如何调查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));
如何保持意图分别调用独立活动?
解决方法:
试试这个:
PendingIntent.getActivity(context, 0 , notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
注意PendingIntent.getActitity方法的最后一个参数.
如果您想知道应该使用哪个FLAG,请参阅api文档 – @H_419_32@[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启动新活动时出现混乱的行为全部内容,希望文章能够帮你解决android – 使用PendingIntent启动新活动时出现混乱的行为所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)