Android Widget Refresh

倾然丶 夕夏残阳落幕 提交于 2019-12-06 10:09:26

问题


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 ?


回答1:


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 );



回答2:


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


来源:https://stackoverflow.com/questions/4337824/android-widget-refresh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!