如何提高我的应用程序的速度?
我的应用程序要求是联系 Web 服务、获取 xml、解析它并使用列表字段显示它。我将所有这些类称为 xmlhandler、objectmodel,使用扩展主屏幕的类中的 lisfield 显示它,这使我的应用程序变慢。
谁能建议我如何让它更快?
是否容易弹出加载屏幕并启动一个线程来联系Web服务,获取xml,解析它并终止线程,然后填充列表屏幕并显示它?
欢迎任何形式的建议!
My applications requirement is to contact the webservice, get the xml, parse it and display it using a listfield. I am calling all this classes xmlhandler, objectmodel, displaying it using a lisfield from a class that extends mainscreen which is making my application slow.
Can anyone suggest me how to make it fast?
Is it a apt to popup a loading screen and start a thread for contacting the webservice, get the xml, parsing it and kill the thread, then populate the listscreen and display it?
suggestions of any kind is welcome!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
测试程序每个部分的速度。我通常使用的是 System.nanoTime() 并在程序的每个部分之后找到时间差异。
Test the speed of every part of your program. What I usually use is
System.nanoTime()
and find the difference in time after every part of the program.在做其他事情之前先找出哪个部分速度慢。
否则,你会在错误的部分上浪费大量时间。
为了进行这种计时工作,我经常将内部日志记录到 StringBuilder 中,或者可能只是记录到保存原始、未格式化数据的 ArrayList 中。测试结束后,我将数据格式化并输出。这可以最大限度地减少日志记录对计时的影响。
Find out which part is slow before you do anything else.
Otherwise, you'll waste a lot of your time on the wrong parts.
For doing this kind of timing work, I often will do internal logging into a StringBuilder, or maybe just into an ArrayList holding raw, unformatted data. After the test is over, I format and output the data. This minimizes the effect of the logging on the timings.
我只能猜测,如果我错了,请原谅我 - 对我来说,只有在真正查看列表字段的项目时,创建列表字段的项目似乎才更有效。因此,我会尝试仅将解析后的字符串保留在内存中,并仅创建当前要显示的 UI 项目,丢弃不可见的内容。为了使其更加流畅,您可以将其在当前页面之前和之后扩展一页或多页。
这样,显示的项目数量始终保持不变。您还可以向服务层添加分页以限制一次传输的记录数量。
I can only gues so forgive me if I'm wrong - to me it seems more efficient to create the item of list field only when they're really viewed. So I'd try to keep in memory only the parsed strings and create only the UI items currently to be displayed, discard invisible. To make it more smooth you can you can extend it one or more pages before and after current page.
This way the number of displayed items is always constant. You may also add paging to the service layer to limit number of records trabsmitted at once.