待处理意图的多个实例

Multiple Instances of Pending Intent(待处理意图的多个实例)
本文介绍了待处理意图的多个实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个小部件,单击该小部件会激活 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);

这篇关于待处理意图的多个实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)
Android + coreLibraryDesugaring: which Java 11 APIs can I expect to work?(Android+core LibraryDesugering:我可以期待哪些Java 11API能够工作?)
How to render something in an if statement React Native(如何在If语句中呈现某些内容Reaction Native)
How can I sync two flatList scroll position in react native(如何在本机Reaction中同步两个平面列表滚动位置)
Using Firebase Firestore in offline only mode(在仅脱机模式下使用Firebase FiRestore)
Crash on Google Play Pre-Launch Report: java.lang.NoSuchMethodError(Google Play发布前崩溃报告:java.lang.NoSuchMethodError)