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