How to update widgets from a service?

前端 未结 1 532
陌清茗
陌清茗 2021-01-01 22:18

I have a background service that can be configured to perform some action every x minutes. I want to implement a widget that gets updated every time my service performs that

1条回答
  •  一生所求
    2021-01-01 23:05

    Just make yourself a RemoteViews and update the widget(s) directly in the Service. You'll get your AppWidgetManager via:

    AppWidgetManager mgr=AppWidgetManager.getInstance(this);
    

    Everything else is as normal.

    Note:- If you really want to force the existing AppWidgetProvider to do the work, send a broadcast with a custom action to your component, and call onUpdate() yourself from onReceive() when you get it.

    0 讨论(0)
提交回复
热议问题