多个实例的widget只更新最新插件 [英] Multiple Instances Of Widget Only Updating Last widget

查看:157
本文介绍了多个实例的widget只更新最新插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个WidgetProvider和配置活动

I have a WidgetProvider and an Configure Activity

在Widget的启动会启动与配置活动,我将它设置通过自定义调用widgetprovider

When the Widget is started it starts with the configure activity and I set it up by making a custom call to the widgetprovider

(你会发现是从SDK实例教程)

(which you will notice is from the sdk tutorial examples)

 // Push widget update to surface with newly set prefix
              AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
              AwarenessWidget.updateAppWidget(context, appWidgetManager,
                      mAppWidgetId, position);

            // Make sure we pass back the original appWidgetId
            Intent resultValue = new Intent();
            resultValue.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
            setResult(RESULT_OK, resultValue);
            finish();

我通过控件ID的功能....小部件内创建一个这样的意图:

I pass the Widget ID to the function.... inside the widget I create a Intent like this:

  Intent configIntent = new Intent(context, Configure.class);
    configIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, appWidgetId);

    PendingIntent pendingIntent = PendingIntent.getActivity
    (context, 0, configIntent,
    PendingIntent.FLAG_UPDATE_CURRENT);

    views.setOnClickPendingIntent(R.id.MainImage,pendingIntent);

    views.setImageViewResource(R.id.MainImage, lv_images[version]);

    appWidgetManager.updateAppWidget(appWidgetId, views);

我一直在引用的部件编号,甚至将其添加为一个额外的意图 但是当我得到两个这些小部件的主屏幕小部件I​​D总是引用最后放置的小部件ID上

I am always referencing the widget ID and even add it as a extra on the intent but when I get two of these widgets on the home screen the widget ID is always referencing the last placed widget ID

推荐答案

我也有类似的问题。只需添加到您配置的活动,在这里设置你的PendingIntent:

I had a similar problem. Just add this to your config activity, where you set your PendingIntent:

Uri data = Uri.withAppendedPath(
    Uri.parse(URI_SCHEME + "://widget/id/")
    ,String.valueOf(appWidgetId));
intent.setData(data);

变量URI_SCHEME是一个字符串,可以是任何你想..即 - ABCD这将导致每个插件都有一个唯一的PendingIntent

The variable URI_SCHEME is a String, and can be whatever you'd like.. ie - "ABCD" This causes each widget to have a unique PendingIntent.

这篇关于多个实例的widget只更新最新插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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