Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to reuse RemoteViews in an appWidget instead of creating new ones every time? and how can I store them?

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.

like image 406
GalDude33 Avatar asked Nov 04 '22 08:11

GalDude33


1 Answers

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.

like image 99
CommonsWare Avatar answered Nov 09 '22 13:11

CommonsWare