setImageViewResource Sometimes loads image and sometimes it doesn't.
- by Niv
Hi All,
I'm writing a simple widget which has an imageview widget that is supposed to load an image dynamically. To do this, I'm starting a service in the onUpdate method of the service. I validated that the service is running, however, the image is loaded only once every 10 times.
Here is the code:
(In the Original extends AppWidgetProvider)
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
Log.d(LOG_TAG, "onUpdate(): Starting Service..1");
context.startService(new Intent(context, UpdateService.class));
}
(The service:)
@Override
public void onStart(Intent intent, int startId) {
Log.d(LOG_TAG, "(OnStart) In On Start..!");
AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(this);
int[] appWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(this, Original.class));
for (int appWidgetId : appWidgetIds) {
RemoteViews remoteView = new RemoteViews(this.getPackageName(), R.layout.widget);
remoteView.setImageViewResource(R.id.widgetImage, R.drawable.let02);
remoteView.setTextViewText(R.id.widget_textview_month, "aaa");
Log.d(LOG_TAG, "(OnUpdate) Set All Fields!");
appWidgetManager.updateAppWidget(appWidgetId, remoteView);
}
//super.onStart(intent, startId);
return;
}