Search code examples
androidonclickandroid-appwidgetappwidgetprovider

Can an appwidget onClick PendingIntent be set from any class? if so, How


I have an appwidget and i want to set an onClick Pending Intent. I would like this PendingIntent to be set from the UpdateService class, not the WidgetProvider class. I've unsuccessfully tried to do it in the same way as i would from the WidgetProvider class.

Edit 2: The issue that caused me to post this question turned out to be unrelated. But having confirmation that it is possible to do it, i kept trying and found that my problem was caused by the onClick appwidget layout item being obscured by higher layers in the appwidget layout.
(edit 1 removed code as it was irrelevant.)


Solution

  • Step #1: Have UpdateService obtain an instance of AppWidgetManager, via the static getInstance() method.

    Step #2: Call updateAppWidget() on the AppWidgetManager.