Service is run once... then never again


I created my app as I wanted a widget to display some status text on my home screen. Upon adding the widget to to home screen it updates to never update again... As a workaround I've added click event to the widget, so the click triggers the update of the widget - but that also dies, in order to fix that I have to open the application, go to my home screen en tap the widget and it will update. After a couple of minutes it does not respond to clicks again. And it never updates the widget by the set interval (updatePeriodMillis).

I've not put my app in the list of application that the OS will sleep.

Anyone have a clue?


  • JarvanJarvan Member, Xamarin Team Xamurai

    Try to use broadcast to achieve updating widget. Override the OnReceive method of widget, send a broadcast to get a message when clicking the widget.

    var piBackground = PendingIntent.GetBroadcast(context, 0, intent, PendingIntentFlags.UpdateCurrent);
    widgetView.SetOnClickPendingIntent(Resource.Id.widgetBackground, piBackground);
    AppWidgetManager manger = AppWidgetManager.GetInstance(context);
    ComponentName thisName = new ComponentName(context, Java.Lang.Class.FromType(typeof(Widget)).Name);
    manger.UpdateAppWidget(thisName, widgetView);

    Refer to:

Sign In or Register to comment.