I’m building a homescreen widget and my goal is to set an image on the ImageView within this widget and I use setImageViewResource() for this. And it works perfectly – means that the target image R.id.user_button changes its image resource to R.drawable.activity_notification after onStart() was executed – if I use it like this:
public class UpdateWidgetService extends Service {
public void onStart(Intent intent, int startId) {
... //Some code which is not really important
RemoteViews remoteViews = new RemoteViews(this.getPackageName(),R.layout.widget_layout);
remoteViews.setImageViewResource(R.id.user_button, R.drawable.activity_notification);
}
}
The problem is I have to put setImageViewResource() inside an external function and when try to build something like the code below it refuses to work – means that image resource of the target image R.id.user_button remains unchanged after onStart() is executed.
public class UpdateWidgetService extends Service {
public void onStart(Intent intent, int startId) {
... //Some code which is not really important
changeImagePicture();
}
public void changeImagePicture() {
RemoteViews remoteViews = new RemoteViews(this.getPackageName(),R.layout.widget_layout);
remoteViews.setImageViewResource(R.id.user_button, R.drawable.activity_notification);
}
}
I guess I’m a noob and I miss something really simple and very important here. Can you please point at my misstake so I can get my code to work at last 😉
Merci beaucoup!
You need to use the updateAppWidget method of the AppWidgetManager class:
Good luck….