android:从 Intent extras 中获得相同的值

发布于 2024-11-16 01:29:51 字数 628 浏览 7 评论 0原文

我这样做是为了创建一个意图。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甩你一脸翔 2024-11-23 01:29:51

使用这个

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文