【问题标题】:onDataSetChanged() in RemoteViewService is not called after notifyAppWidgetViewDataChanged在 notifyAppWidgetViewDataChanged 后未调用 RemoteViewService 中的 onDataSetChanged()
【发布时间】:2022-07-29 16:37:47
【问题描述】:

在我的 AppWidgetProvider 类中,onUpdate() 方法中有以下代码:

    // Update each of the widgets with the remote adapter
    for (int appWidgetId : appWidgetIds) {
        HyperLog.i(TAG, "Updating Widget id " + appWidgetId);

        ...

        HyperLog.i(TAG, "Starting updateAppWidget with id " + appWidgetId);
        appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetId, R.id.lvActiveReminders);
        appWidgetManager.updateAppWidget(appWidgetId, rv);
    }
    super.onUpdate(context, appWidgetManager, appWidgetIds);

但是调用notifyAppWidgetViewDataChanged()并没有调用RemoteViewService类方法onDataSetChanged()

        HyperLog.i(TAG, "onDataSetChanged is called.");
        getData();

有没有人暗示为什么不调用它?

始终调用 AppWidgetProvider 中的 onUpdate() 并且 updateAppWidget 刷新小部件,但使用旧数据,因为之前未调用 onDataSetChaned()
在文档中,这是我们刷新小部件数据的方式 (https://developer.android.com/guide/topics/appwidgets/collections#keep-data-fresh)。

我正在 Android 12 设备上对此进行测试。

【问题讨论】:

    标签: android android-widget


    【解决方案1】:

    在 2 个月内对不同型号的智能手机和不同的 Android 版本进行了大量测试后,我得出了结论问题出在制造商的操作系统更新

    因为

    1)。我的智能手机 OnePlus 8T 和 Android 12 没有问题,就像你的一样,直到 2022 年 5 月的最后一次操作系统更新。安装最后一次更新后,我遇到了你描述的同样的问题:我的小部件已更新,但小部件的列表视图没有'不经常更新 - onDataSetChanged 不会启动。

    2)。我朋友的同一部智能手机 OnePlus 8T 与 Android 12,但没有从 2022 年 5 月开始的最后一次更新,在 onDataSetChanged 上没有任何问题 - listview 已更新,一切工作 100% 稳定。

    3)。在搭载 Android 12 的三星上没有任何问题:onDataSetChanged 对 NotifyAppWidgetViewDataChanged 做出反应。

    4)。在搭载 Android 10、11 onDataSetChanged 的​​智能手机上运行稳定。

    【讨论】:

      猜你喜欢
      • 2016-02-25
      • 1970-01-01
      • 2018-03-06
      • 1970-01-01
      • 2012-09-06
      • 1970-01-01
      • 1970-01-01
      • 2015-06-18
      • 2012-10-24
      相关资源
      最近更新 更多