[英]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: 在我的appWidgetProvider中,每次需要更新appWidget时,都必须创建一个新的RemoteViews对象并为其分配属性:
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. 但实际上,我只需要更改一件事,即TextView Text。
Can I somehow store the RemoteViews for reusing it on the next update, and just applying 我可以以某种方式存储RemoteView以便在下一个更新中重用它,并仅应用
view.setTextViewText(R.id.nick,wParameters.getNick());
appWidgetManager.updateAppWidget(appWidgetId, views);
again? 再次?
Or get the previously used RemoteViews object somehow? 还是以某种方式获取先前使用的RemoteViews对象?
I want to achieve this because the process of setting the new RemoteViews object properties again is very expensive in my appWidget. 我想要实现这一点,因为在我的appWidget中再次设置新的RemoteViews对象属性的过程非常昂贵。
Let's assume my widget is made of a TextView and a ImageView. 假设我的小部件由TextView和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. 在窗口小部件的configureActivity中选择ImageView的图像(对于appWidget的每个实例都是唯一的),但是图像处理非常昂贵。 the TextView text is needed to be changed in every update. TextView文本需要在每次更新中进行更改。 I want to leave the ImageView image as it is, and only change the text of the TextView. 我想保持ImageView图像不变,只更改TextView的文本。 is it posible to update the TextView without updating the imageView? 是否可以在不更新imageView的情况下更新TextView?
Will be glad for any help and ideas! 如有任何帮助和想法,我们将非常高兴! Thanks advanced, Gal. 谢谢你,加尔
But in fact, I only need to change one thing which is the TextView Text. 但实际上,我只需要更改一件事,即TextView Text。
Then only change "the TextView Text". 然后仅更改“ TextView文本”。
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. AFAIK,只要保持相同的布局ID,就不需要更新布局中的每个小部件。 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 我可以以某种方式存储RemoteView以便在下次更新时重用它
No. 没有。
Or get the previously used RemoteViews object somehow? 还是以某种方式获取先前使用的RemoteViews对象?
No. 没有。
I want to achieve this because the process of setting the new RemoteViews object properties again is very expensive in my appWidget. 我想要实现这一点,因为在我的appWidget中再次设置新的RemoteViews对象属性的过程非常昂贵。
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. 然后在由AppWidgetProvider
启动的IntentService
进行工作,就好像它是如此昂贵一样,您不想在主应用程序线程上进行这项工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.