Performance RemoteViews in Android

半世苍凉 提交于 2020-01-05 04:28:13

问题


I am trying to write a small application in Android. My application is on Widgets. I have a basic doubt on using RemoteViews. I found that whenever , I update some button or some UI layout a new object of the remoteviews is created . Will that be a problem with the performance? an example code is this:

http://android-developers.blogspot.com/2009/04/introducing-home-screen-widgets-and.html

updateViews = new RemoteViews(context.getPackageName(), R.layout.widget_message);

even for updating the views everytime, new remoteview object is created. Please help me in understanding this.


回答1:


No it isn't a problem. I'm working with StackViewsWidget example to build a honeycomb widget that has a RemoteViews for each card in the deck of views that shuffle buy, and each card is recycled and rebuilt from what I can tell in the debugger, and it's smooth as butter flipping through the views on my Xoom.




回答2:


You might consider creating only one object using singleton pattern. This can be done by implementing a singleton for your RemoteViews class and then using this singleton to create an object of RemoteViews. Actually the problem lies with the memory of the machine on which you are running the android app. If you are able to scale that up by doing some profiling and performance settings then you can very well create new objects using the above code. But if you have a limitation then I would suggest the singleton pattern. This solution assumes that the machine you are working on has enough processing power.



来源:https://stackoverflow.com/questions/4211149/performance-remoteviews-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!