待定意向的多张实例 [英] Mulitple Instances of Pending Intent

查看:160
本文介绍了待定意向的多张实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个小窗口,单击时激活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);

这篇关于待定意向的多张实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆