5

In my appWidgetProvider, every time I need to update an appWidget I have to create new RemoteViews object and assign it's properties:

RemoteViews views = new RemoteViews(context.getPackageName(),layout);
views.setOnClickPendingIntent(R.id.widgetLayout, pendingIntent);
view.setFloat(R.id.nick, "setTextSize", wParameters.getFontSize()); 
view.setTextViewText(R.id.nick,wParameters.getNick()); 
.........etc

appWidgetManager.updateAppWidget(appWidgetId, views);

But in fact, I only need to change one thing which is the TextView Text.

Can I somehow store the RemoteViews for reusing it on the next update, and just applying

 view.setTextViewText(R.id.nick,wParameters.getNick()); 
 appWidgetManager.updateAppWidget(appWidgetId, views);

again?

Or get the previously used RemoteViews object somehow?

I want to achieve this because the process of setting the new RemoteViews object properties again is very expensive in my appWidget.

Let's assume my widget is made of a TextView and a ImageView. The ImageView's image is chosen in the widget's configureActivity (unique for every instance of the appWidget), but the image procssing is expensive. the TextView text is needed to be changed in every update. I want to leave the ImageView image as it is, and only change the text of the TextView. is it posible to update the TextView without updating the imageView?

Will be glad for any help and ideas! Thanks advanced, Gal.

GalDude33
  • 7,071
  • 1
  • 28
  • 38

1 Answers1

2

But in fact, I only need to change one thing which is the TextView Text.

Then only change "the TextView Text".

AFAIK, so long as you are keeping the same layout ID, you do not need to update every widget in the layout if you do not want to. However, it is incumbent upon you to always know whether the app widget had been rendered previously, and that can get tricky. It is usually simpler, therefore, to update every widget every time.

Can I somehow store the RemoteViews for reusing it on the next update

No.

Or get the previously used RemoteViews object somehow?

No.

I want to achieve this because the process of setting the new RemoteViews object properties again is very expensive in my appWidget.

Then do the work in an IntentService kicked off by your AppWidgetProvider, as if it is that expensive, you do not want to be doing that work on the main application thread.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • I cant only change "the TextView Text". Let assume my widget is made of a TextView and a ImageView. The ImageView's image is constant and is chosen in the widget's configureActivity (unique for every instance of the appWidget). (the image procssing is the expensive part). the TextView text is needed to be changed in every update. I want to leave the ImageView image as it is, and only change the text of the TextView. is it posible to update the TextView without updating the imageView? – GalDude33 Dec 29 '11 at 20:59
  • 1
    since API11 there is a function: appWidgetManager.PartiallyUpdateAppWidget(appWidgetId, views); I'm trying to achieve the same effect for API8. – GalDude33 Dec 29 '11 at 21:10
  • @GalDude33: "the image procssing is the expensive part" -- which is why you need to be saving the modified image in a file and making it available to the app widget host via a `ContentProvider`. After all, people do reboot their phones, and from what you're describing, when they reboot their phone, they lose their image. Once you save the image, then the image processing is not done on every update, so the updates become inexpensive. That being said, the existence of `partiallyUpdateAppWidget()` indicates that my original assessment was probably incorrect, for which I apologize. – CommonsWare Dec 29 '11 at 21:26