0

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.)

1 Answers1

0

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

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

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I have done this to reliably update text in my widget. but an onclick pending intent sent with those updates, or separately, does not work. There must be something really simple im missing but i have been searching unsuccessfully for days. Ive tried many things and copied a number of examples and cant get it to work. –  Apr 06 '14 at 17:00
  • @kodintent: Please define "does not work". You may also wish to edit your question to provide the code that you are using to update the `AppWidgetManager` with the `PendingIntent`. If "does not work" means "my extras are not changing", be sure that you are using something like [`FLAG_UPDATE_CURRENT`](https://developer.android.com/reference/android/app/PendingIntent.html#FLAG_UPDATE_CURRENT) when creating your revised `PendingIntent`. – CommonsWare Apr 06 '14 at 17:13
  • My onClickPI was working but the layout item i had set for the action was obscured under higher layers. However i still dont know the rules regarding which layers obscure. –  Apr 06 '14 at 20:06
  • 1
    @kodintent: An app widget is no different than anything else in that regard -- it is based on the Z-axis order of the widgets. – CommonsWare Apr 06 '14 at 20:15