Android小部件刷新

时间:2010-12-02 17:20:35

标签: android widget onupdate

我已经实现了一个小部件但是在刷新时遇到了问题。 我得到了最初的onUpdate,如果我把它放了很长时间,我会再次。

但是我希望主应用程序中的更改能够自动反映在窗口小部件上。 我该如何刷新? 有没有办法从我的Activity中调用窗口小部件(我只是做一个静态例程)还是有办法在每次手机返回主屏幕时强制调用“onUpdate”?

2 个答案:

答案 0 :(得分:3)

您是否使用服务更新RemoteView实现了窗口小部件?如果是这样,您可以使用Intent启动该服务,并且小部件将更新。

Intent widgetUpdateIntent = new Intent(context, MyClassName.UpdateService.class);
context.startService(widgetUpdateIntent );

答案 1 :(得分:1)

AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager//.setRepeating(AlarmManager.RTC_WAKEUP, 500, 2, pendingIntent1);
.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 500, pendingIntent1);