setImageViewResource Sometimes loads image and sometimes it doesn't.

Posted by Niv on Stack Overflow See other posts from Stack Overflow or by Niv
Published on 2010-12-24T21:51:21Z Indexed on 2010/12/24 21:54 UTC
Read the original article Hit count: 174

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;
}

© Stack Overflow or respective owner

Related posts about android-widget

Related posts about imageview