简体   繁体   English

是否可以在appWidget中重用RemoteViews而不是每次都创建新的? 以及如何存储它们?

[英]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.

相关问题 如何重用我的JFrame来一个接一个地显示几个GUI,而不是为每个GUI创建一个新的JFrame? - How can I reuse my JFrame to show several GUIs one after the other, instead of creating a new JFrame for each? 每当我从键盘(java)输入新数字时,如何将数字存储到数组中? - How can I store numbers into array every time I input a new number from keyboard (java)? 如何存储cookie,并在另一个会话中重用它们 - How to store cookies, and reuse them in another session 我应该重用一个GSON实例还是按需创建新实例? - Should I reuse one instance of GSON or create new ones on demand? 只有一个有效的testCase,我可以节省编写失败的时间吗? (我可以自动生成它们吗) - Only one valid testCase, can I save the time to write failing ones? (can I automatically generate them) 每次启动服务器时如何停止Eclipse(STS)创建新的运行时配置 - How do I stop Eclipse (STS) from creating a new runtime configuration every time I start a server 重用对象实例与每次更新创建新对象 - Reusing instances of objects vs creating new ones with every update 每次遍历列表时都创建一个新的迭代器对象 - Creating a new iterator object every time I traverse the list Android:使用全局对象而不是创建新对象 - Android: use a global object instead of creating new ones ArrayList重用单个对象,而不是创建新的对象 - ArrayList re-using single Object, instead of creating new ones
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM