待定意向的多张实例

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

我创建了一个小窗口,单击时激活PendingIntent。问题是,当我有一个以上的插件的屏幕上只有最新一期将启动PendingIntent。

我看了一些关于独特的请求code,但没有想通了这一点。

任何想法如何,我可以有多个部件和PendingIntents每个工作?

下面是我的code的一个片段:

意图openApp =新的意图(背景下,RunningTally.class);     openApp.putExtra(为widgetid,appWidgetId);     PendingIntent pendingAppIntent =         PendingIntent.getActivity(上下文,0,openApp,PendingIntent.FLAG_CANCEL_CURRENT);     views.setOnClickPendingIntent(R.id.openFull,pendingAppIntent);

解决方案

恰巧张贴我的问题后,我想出了一个答案。我通过我的appWidgetId为独一无二的请求,code,瞧!这里是目前片段:

意图openApp =新的意图(背景下,RunningTally.class);     openApp.putExtra(为widgetid,appWidgetId);     PendingIntent pendingAppIntent =         PendingIntent.getActivity(背景下,appWidgetId,openApp,                                   PendingIntent.FLAG_CANCEL_CURRENT);     views.setOnClickPendingIntent(R.id.openFull,pendingAppIntent);

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.

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

Here is a snippet of my code:

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);

解决方案

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:54:43,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1637047.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:待定   多张   意向   实例

发布评论

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

>www.elefans.com

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