Android Widget Refresh

2019-04-14 09:56发布

I have implemented a widget but have problems refreshing it. I get the initial onUpdate , and again if I leave it for ages.

However I want changes in my main application to be automatically reflected on the widget. How do I get that to refresh ? Is there a way of calling the widget from my Activity (do I just do a static routine) or is there a way I can force my "onUpdate" to be called each time the phone returns back to the home screen ?

2条回答
甜甜的少女心
2楼-- · 2019-04-14 10:38
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager//.setRepeating(AlarmManager.RTC_WAKEUP, 500, 2, pendingIntent1);
.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 500, pendingIntent1);
查看更多
看我几分像从前
3楼-- · 2019-04-14 10:42

Did you implement your widget using a service to update the RemoteViews? If so you can kick off that service with an Intent and the widget will update.

Intent widgetUpdateIntent = new Intent(context, MyClassName.UpdateService.class);
context.startService(widgetUpdateIntent );
查看更多
登录 后发表回答