I'm sure I'm missing something, but I'm just trying to get an app widget with a button and a counter. Every time I click the button I want the counter to update by 1.
I've set the onUpdate() function of the WidgetProvider to register a pending event to the button so that it starts a service to bump the counter numbver:
Intent active = new Intent(context, CounterService.class);
active.setAction(CounterService.COUNT);
PendingIntent pending = PendingIntent.getService(context, 0, active, PendingIntent.FLAG_UPDATE_CURRENT);
views.setOnClickPendingIntent(R.id.CountButton, pending);
ComponentName component = new ComponentName(context.getPackageName(), KickCounterWidgetProvider.class.getName());
appWidgetManager.updateAppWidget(component, views);
Then in the services CounterService::onStart() function I bump the count (stored in prefs for now) and then try and update the text field that shows the current count value:
// ... bump the count here and store a string representation of it in currentCountString ...
RemoteViews remoteView = new RemoteViews(getApplicationContext().getPackageName(), R.layout.widget);
remoteView.setTextViewText(R.id.CurrentKickCount, currentCountString);
// apply changes to widget
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(getApplicationContext());
ComponentName component = new ComponentName(getApplicationContext().getPackageName(), KickCounterWidgetProvider.class.getName());
appWidgetManager.updateAppWidget(component, remoteView);
Judicious use of Logcat indicates tha this all works ok and the string seems to be OK, but for some reason the call to appWidgetManager.updateAppWidget() seems to be failing silently for some reason.
I don't know if it's related at all, but the first time I add an instance of the widget to the homescreen, not even the button works (ie the call to updateAppWidget() in onUpdate() in the Provider fails). Subsequent instances of the widget seem to work OK for the call to updateAppWidget() in the Provider but never works for the service.
Any help would be greatly appreciated.