Updating a unique AppWidgetProvider from a Service

by theSmith » Sat, 02 Jan 2010 11:12:47 GMT

Sponsored Links
 Here is my issue, I want to be able to update a specific
AppWidgetProvider (home screen widget) from a custom service class.  I
have to build the remote view in the service because I'm also doing
some networking in there, which takes some time.

The problem is that I can't figure out how to update a specific widget
(individual widgets can have different update intervals, using the
alarm manager).

If I wanted to do it from the onUpdate of the AppWidgetProvider I
could just call appWidgetManager.updateAppWidget(appWidgetId,

Does anyone have any experience with this or any suggestions?



Updating a unique AppWidgetProvider from a Service

by theSmith » Mon, 04 Jan 2010 00:17:57 GMT

 To follow up on my own question, heres how I did it.

I went from a service to an IntentService and in the onHandleIntent
(Intent intent) I handle the update requests.

To get the individual id's I put them as an extra in the intent in the
onRecieve() method in the widget, then fire them off to the
IntentService with context.startService(i).  Everything is working
perfectly now.



Sponsored Links

Updating a unique AppWidgetProvider from a Service

by Lyndon » Thu, 14 Jan 2010 00:54:22 GMT


I have the same problem so thanks very much for the post...

Could you explain how the onHandleIntent method works please.

I have the appWidgetId in the service so I just need the way to update
that specific widget.

Any help would be very much appreciated.



> - Show quoted text -

Updating a unique AppWidgetProvider from a Service

by theSmith » Fri, 15 Jan 2010 06:58:20 GMT

 No problem, heres how I did it.

AppWidgetManager manager = AppWidgetManager.getInstance(this);
RemoteViews views = new RemoteViews(context.getPackageName(),
views.setTextViewText(R.id.TextView_Body, "hello world");
appWidgetManager.updateAppWidget(appWidgetId, views);

onHandleIntent is called every time you use context.startService
(intent);  Just make sure to use that intent to send the appWidgetId
you need updated.  If the IntentService is not already running then
its onCreate() is called, other wise the intent is put into a FIFO
queue.  the onHandleIntent method runs on a seperate thread than the
rest of the app, even the IntentService's onCreate().  This allows you
to do time consuming processes like networking without android giving
the user a ANR dialog.

If you want to probe my brain some more feel free to ask.


> > - Show quoted text -

Other Threads

1. aPad/iRobot 2nd generation bisa disambung ke 3G/HSPA USB dongl

Kabar terbaru, sudah positif bisa disambung ke beberapa modem USB
(Huawei EG162G dan Vtion e1916! )
Secara otomatis setelah disambungkan, nanti akan muncul dialer
software untuk dial ke modemnya. Keren!!!!!

Kalo ada yang punya USB modem dan aPAD, dipersilahkan untuk
mencoba...saya gak punya USB modem :(
Kalo sukses, please report yah modem apa aja yang mumpuni.


"Indonesian Android Community [id-android]" 

2. Class ServiceManager missing in Android 2.1


I am trying to change the DNS settings of Android phone,

I need to use the following class:

These classes are available in Android 1.5 but they dont exist in
Android 2.1.
Are they replaced by any other class in 2.1?

Any pointers on the substitute classes available in Android2.1?



3. Latency due to Garbage collection on onPrevFrame

4. IM Native..again....

5. How to apply background color to all the activities

6. Clearing all the Task within an application while activity launch

7. Android porting to TV