以编程方式更新的活动/服务/接收器插件 [英] Programmatically update widget from activity/service/receiver
本文介绍了以编程方式更新的活动/服务/接收器插件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道这是可能的,但我不能想出一个办法,从主要活动触发我的窗口小部件的更新。是不是有一些通用的意向,我可以播出?
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?
推荐答案
如果您的是的使用AppWidgetProvider,你可以更新它是这样的:
If you are using an AppWidgetProvider, you can update it this way:
Intent intent = new Intent(this,MyAppWidgetProvider.class);
intent.setAction(AppWidgetManager.ACTION_APPWIDGET_UPDATE);
// Use an array and EXTRA_APPWIDGET_IDS instead of AppWidgetManager.EXTRA_APPWIDGET_ID,
// since it seems the onUpdate() is only fired on that:
int[] ids = {widgetId};
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS,ids);
sendBroadcast(intent);
这篇关于以编程方式更新的活动/服务/接收器插件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文