I'm having an issue with binding click events to an app widget with Xamarin Android. The clicks are working, and are launching the activity, but the information passed along to differentiate the widgets is not working. It appears that the same intent is being registered for all instances of the widget.
Below is a cut down sample of the code doing the click binding from a service. The full code also updates text on the widgets. That part is working fine, and is different on each instance of the widget, so I believe the overall update pattern is correct. That leaves me with the intent/pending intent binding as the problem. Is there something wrong with the pattern I'm using below?
public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
{
var manager = AppWidgetManager.GetInstance(this);
var ids = intent.GetIntArrayExtra(AppWidgetManager.ExtraAppwidgetIds);
foreach (var id in ids)
{
var widgetView = new RemoteViews(PackageName, Resource.Layout.SingleRateWidget);
var activityIntent = new Intent(this, typeof(ExchangesActivity));
activityIntent.SetFlags(ActivityFlags.ClearTop | ActivityFlags.NewTask);
activityIntent.PutExtra("WidgetId", id);
var pendingIntent = PendingIntent.GetActivity(this, 0, activityIntent, PendingIntentFlags.UpdateCurrent);
widgetView.SetOnClickPendingIntent(Resource.Id.widgetBackground, pendingIntent);
manager.UpdateAppWidget(id, widgetView);
}
return StartCommandResult.Sticky;
}
Thanks.