Search code examples
androidserviceemulationwidgetremoteview

Updating Widgets from a Service via RemoteViews - OK on a phone, not working on the Emulator


I've created a WidgetProvider and a Service which triggers on the system TIME_TICK - that part is working fine, Log messages show the Service is working AOK and it looks great on an actual phone.

To update my Widgets I use code like this (editted for clarity so it might have a typo)

    Log.d("xxx","Updating");
    RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.main);
    views.setTextViewText(R.id.appwidget_text, "Some Text" + System.currentTimeMillis());
    ComponentName thisWidget = new ComponentName(context, SWClockWidgetProvider.class);
    AppWidgetManager manager = AppWidgetManager.getInstance(context);
    manager.updateAppWidget(thisWidget, views);

On my phone (an HTC Desire running 2.2) it's perfect, the Widgets update bang-on the minute, every minute.

On the emulator (running 2.2) Log messages appear (e.g. the service is working) but widgets aren't updated.

Now I call that code in 2 places - from the onUpdate method of the Provider (so that it puts something into the Widgets when they're first displayed) and from the Service's listener (to update them)

Now here's the weird bit - in my manifest I originally declared my service like this

service android:name=".SWClockWidgetService"

When I changed that to explicitly mention the package (which is identical to the Provider's package of course)

service android:name="com.somewhatdog.swclockwidget.SWClockWidgetService"

the initial update (called from the Provider onUpdate) works BUT subsequent calls from the Service's listener still don't!?

Note: Originally I made the Service an inner-class of the provider but that didn't work on a phone OR emulator - no idea if that's related...

Anyway - I'm mystified - same Android on phone and emulator - one works, one doesn't (which means the odds of this working on other devices are moody to say the least??)

I'm more than a bit lost here - any advice apprec.

p.s. I've tested this on an emulator running 1.6 no joy - it works on an emulator running 2.1r1 and 2.3.3 tho, so who knows...


Solution

  • Much further experimentation suggests that Widget updating within the Emulator is just broken.

    Even if you deploy new code, existing Widgets remain unchanged!

    Testing using Androidx86 suggests the problem is confined to the emulator tho - so I guess I'll use that for Widget testing instead...