有多个待定意图

编程入门 行业动态 更新时间:2024-10-24 18:28:48
本文介绍了有多个待定意图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我创建了一个小部件,单击该小部件可以激活PendingIntent.问题是,当我在屏幕上有多个控件时,只有最新的控件会启动PendingIntent.

I created a widget that when clicked activates a PendingIntent. The problem is when I have more than one widget on the screen only the latest one will start the PendingIntent.

我已经阅读了一些有关唯一请求代码的信息,但并未弄清楚.

I have read some about a unique request code, but not figured this out.

有什么想法可以让我有多个小部件,而PendingIntents可以用于每个小部件吗?

Any ideas how I can have multiple widgets and the PendingIntents work for each?

这是我的代码段:

Intent openApp = new Intent(context, RunningTally.class); openApp.putExtra("widgetId", appWidgetId); PendingIntent pendingAppIntent = PendingIntent.getActivity(context, 0, openApp, PendingIntent.FLAG_CANCEL_CURRENT ); views.setOnClickPendingIntent(R.id.openFull, pendingAppIntent);

推荐答案

在发布我的问题后,我想到了答案.我将我的appWidgetId传递为唯一"请求代码,瞧!现在是以下代码段:

So happens that after posting my question, I came up with an answer. I pass in my appWidgetId as the "unique" request code and voila! Here is the snippet now:

Intent openApp = new Intent(context, RunningTally.class); openApp.putExtra("widgetId", appWidgetId); PendingIntent pendingAppIntent = PendingIntent.getActivity(context, appWidgetId, openApp, PendingIntent.FLAG_CANCEL_CURRENT); views.setOnClickPendingIntent(R.id.openFull, pendingAppIntent);

更多推荐

有多个待定意图

本文发布于:2023-11-27 06:55:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637049.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   意图   待定

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!