2

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 ?

Chris
  • 629
  • 3
  • 8
  • 14

2 Answers2

3

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 );
GeekYouUp
  • 1,651
  • 11
  • 10
  • 1
    I am not sure how I would setup a service within the widget to service the remote views. Is there an example you can point me at ? – Chris Dec 02 '10 at 18:35
  • Is it not possible to have my application activity send an event to the widget to refresh ? – Chris Dec 02 '10 at 18:54
  • Finally got it, you meant have a service update the widget and then I can call the service from anywhere. Did that - works a treat, thanks ! – Chris Dec 03 '10 at 14:27
  • Great, if it is solved can you close this question please by clicking the 'tick'. cheers. – GeekYouUp Dec 03 '10 at 17:25
1
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager//.setRepeating(AlarmManager.RTC_WAKEUP, 500, 2, pendingIntent1);
.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, 500, pendingIntent1);
jjnguy
  • 136,852
  • 53
  • 295
  • 323
Toshe
  • 459
  • 1
  • 6
  • 20