我创建了一个小窗口,单击时激活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);
更多推荐
待定意向的多张实例
发布评论