Yes, it's possible for a service (or any other piece of code) to update widgets at any time:

AppWidgetManager.updateAppWidget(ComponentName provider, RemoteViews views)

updates *all* widgets specified by the "provider".

If you are using the Wikpedia sample widget, I believe that's how it's done already.

Now, how would the code know it's time to update? An AppWidgetProvider is a subclass of BroadcastReceiver, so just add broadcast actions you are interested in to the widget provider's intent filter in the manifest, next to:

<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />

Like this:

<action android:name="android.bluetooth.adapter.action.STATE_CHANGED" />

Or whatever action you are interested in.

-- Kostya

03.09.2010 10:07, cool.manish пишет:
Thanks Kostya, for sharing this information,
I need one more information: If my service class after complition wish
to update the activity class, how can we do it?

I am just a beginner and haven't much knowledge of android.

On Sep 1, 1:24 am, Kostya Vasilyev<[email protected]>  wrote:
   One more thing:

Android uses the same Linux process for your WidgetProvider as well as
service that updates the widget (again, I'm assuming you followed the
Wikipedia sample).

The WidgetProvider will be created and invoked as necessary, this, in
turn, should cause your service to be started when you call
"startService(this, UpdateService.class)".

A task killer is likely to interfere with the first part of this
sequence - i.e. preventing the WidgetProvider from responding to update
events in the first place.

-- Kostya

31.08.2010 23:50, Kostya Vasilyev О©╫О©╫О©╫О©╫О©╫:





If your code is set up along the lines of the Wikipedia sample widget
(which it seems to be), and the widget's onUpdate invokes the service
with startService, then everything should be fine already.
StartService will, obviously, start the service as necessary.
If there are still problems updating the widget, ask your user to add
your service to the task killer's exclude list. Better yet, try to
educate the user about the evil nature of task killers, perhaps he/she
will stop using them altogether.
--
Kostya Vasilyev --http://kmansoft.wordpress.com
31.08.2010 22:14 О©╫О©╫О©╫О©╫О©╫О©╫О©╫О©╫О©╫О©╫О©╫О©╫ "Alex"<[email protected]
<mailto:[email protected]>>  О©╫О©╫О©╫О©╫О©╫О©╫О©╫:
What is the correct way to ensure that a widget update service is
restarted if it has been killed?
In my widget, I start the service in the onUpdate event, but if the
widget and service are killed (by a task killer, for example), the
widget restarts, but the service doesn't.
On Aug 31, 6:01 pm, Kostya Vasilyev<[email protected]
<mailto:[email protected]>>  wrote:
   A Service can still get killed ...
http://developer.android.com/reference/android/app/Service.html#Proce...
-- Kostya
31.08.2010 20:48, Agus О©╫О©╫О©╫О©╫О©╫:
A thread hosted by the ApplicationContext ...
On Tue, Aug 31, 2010 at 9:22 AM, Kostya
Vasilyev<[email protected]<mailto:[email protected]>>    wrote:
   The difference is that Activity lifecycle is managed by the
user, and
Service lifecycle ...
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group...
--
Kostya Vasilyev -- WiFi Manager + pretty widget --http://kmansoft.wordpress.com


--
Kostya Vasilyev -- WiFi Manager + pretty widget -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to