Is it possible to reuse RemoteViews in appWidget, and not create new ones every time? and how can i store them?

In my appWidgetProvider application, every time I need to update the appWidget application, I need to create a new RemoteViews object and assign it 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 actually I only need to change one thing, which is TextView Text.

Is it possible to somehow save RemoteViews for reuse it at the next update and just apply

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

again?

Or get a previously used RemoteViews object?

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

Suppose my widget is made from TextView and ImageView. An ImageView image is selected in the configureActivity widget (unique to each instance of appWidget), but image processing is expensive. TextView text needs to be changed in every update. I want to leave the ImageView image as it is, and change the text of the TextView only. Is it possible to update TextView without updating the image?

I will be happy for any help and ideas! Thanks, advanced, Gal.

+4
source share
1 answer

But actually I only need to change one thing, which is TextView Text.

Then change only the text of the TextView.

AFAIK, if you keep the same layout ID, you do not need to update each widget in the layout if you do not want it. However, you should always know if the application widget was previously displayed, and this can become complicated. Therefore, it is usually easier to update each widget every time.

Is it possible to save RemoteViews in some way so that I can reuse it next time I upgrade

No.

Or get a previously used RemoteViews object?

No.

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

Then do the work in the IntentService using the AppWidgetProvider , as if it were so expensive, you do not want to do this work in the main thread of the application.

+2
source

Source: https://habr.com/ru/post/1388508/


All Articles