android:从 Intent extras 中获得相同的值
我这样做是为了创建一个意图。
Intent notificationIntent = new Intent(this, Startup.class);
notificationIntent.putExtra("url", contentUrl);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
在获取额外内容时,
CharSequence url = this.getIntent().getCharSequenceExtra("url");
有许多 Intent 及其各自的 url 值。但我也在 Startup 类的 onCreate() 中得到了相同的值。
我做错了什么?
I am doing this to create a Intent.
Intent notificationIntent = new Intent(this, Startup.class);
notificationIntent.putExtra("url", contentUrl);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification(icon, tickerText, when);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
On getting the extra,
CharSequence url = this.getIntent().getCharSequenceExtra("url");
There are many Intents with their respective url values. But I also get back the same value inside onCreate() of Startup class.
What did I do wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这应该肯定会回答你的问题......干杯:)
Android 不断缓存我的意图额外,如何声明一个保留新鲜额外内容的未决意图?
This should answer you query for sure...cheers :)
Android keeps caching my intents Extras, how to declare a pending intent that keeps fresh extras?
使用这个
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notificationIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
而不是这个
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
并检查结果
Use this
PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
notifyIntent, android.content.Intent.FLAG_ACTIVITY_NEW_TASK);
instead of this
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
and check the results