How to update App Widget with list view from an Activity

前端 未结 2 1569
你的背包
你的背包 2021-02-19 01:02

I know this has been asked for many times but I went through the documentation from top to bottom, read all answers here and none of them helped. To be honest, each answer says

2条回答
  •  逝去的感伤
    2021-02-19 01:34

    I would say that notifyAppWidgetViewDataChanged method should work for you.

    You have to build AppWidgetManager and get appWidgetIds and then just call notifyAppWidgetViewDataChanged on your AppWidgetManager.

    Pseudo Code,

    AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
    int appWidgetIds[] = appWidgetManager.getAppWidgetIds(
                               new ComponentName(context, WidgetProvider.class));
    appWidgetManager.notifyAppWidgetViewDataChanged(appWidgetIds, R.id.listview);
    

    For more, you can checkout my answer here which contains demo on github.

提交回复
热议问题