Use RemoteViews.setImageViewResource / setImageViewUri / setImageViewBitmap.

You will most likely need something to track the current state (which image to display).

Regarding your other question: registering a broadcast receiver in a service's onCreate makes sure that it's registered once and only once during the service's lifetime. If the service is killed or stopped, next time the service is created it will create and register a new receiver (don't forget to unregister the receiver in onDestroy).

On the other hand, keeping a service running just for a receiver's sake is considered a poor design pattern. If the broadcast you're interested in is "sticky", you can gets its most recent value with registerReceiver(null, intentFilter). If you do this periodically, driven by AlarmManager updates, you'll be able to track the broadcast's values and not have an "eternal" service.

-- Kostya

09.05.2011 21:59, Boozel ?????:
I have a widget and when it is pressed it runs a service. the code is below. How can i change the image/icon of the widget when it is pressed (not just while it is pressed until the next time it is pressed again). Any help would be great. thanks.

public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
       final int N = appWidgetIds.length;
       globalCon=context;
// Perform this loop procedure for each App Widget that belongs to this provider
       for (int i=0; i<N; i++) {
           int appWidgetId = appWidgetIds[i];
           Log.i(TAG,"Widget onUpdated");
           // Create an Intent to launch ExampleActivity
Intent intent = new Intent(context, SignalSpotWidgetService.class); PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);

// Get the layout for the App Widget and attach an on-click listener to the button RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.widget_layout); views.setOnClickPendingIntent(R.id.widgetButton, pendingIntent); // Tell the AppWidgetManager to perform an update on the current App Widget
           appWidgetManager.updateAppWidget(appWidgetId, views);
   }
}
--
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


--
Kostya Vasilyev -- 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