I know it's possible, but I can't figure out a way to trigger an update of my widget from the main activity. Isn't there some general intent I can broadcast?
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
If you are using an
AppWidgetProvider
, you can update it this way:Just get an
AppWidgetManager
instance and update it directly. Or, if you are using anIntentService
to do the updates, callstartService()
on theIntentService
. TheAppWidgetProvider
is a way to update the app widget, but it is not the only way.So to update an widget from an activity, you can do it like this:
Works for me :)
In case you are working with a widget that uses a collection such as ListView, GridView, or StackView, to update the widget's items, do as follow:
With this method notifyAppWidgetViewDataChanged(), you can force the widget items to fetch any new data in real time.
This helped when I searched on how to update a widget from a service/or action (but may be possible from every Context):
Phaethon's accepted solution in Kotlin:
Where MyAppWidgetProvider is derived from AppWidgetProvider:
class MyAppWidgetProvider : AppWidgetProvider() {