How to reduce App's CPU usage in Android phone?

吃可爱长大的小学妹 提交于 2019-12-06 16:05:55

The reason it's using 50% of your CPU is that Android apparently won't let it use 100% of the CPU, which a loop like the one in your TimeDelay() ordinarily would. (Or else you have two CPUs and it is in fact using 100% of one CPU.) What you're doing is called a busy wait and it should be obvious why continually checking a condition will use lots of CPU. So don't do that. Use Thread.sleep() instead. Your app will then use no CPU at all during the wait.

Also, for God's sake, why are you passing a string and then parseInting it, rather than just passing an Integer in the first place? :-)

TuanAnh

If your method take a long time to finish , especially the while loop. You should put Thread.sleep(50) inside your loop. This makes you processor be able to handle other processes.

Your CPU will be reduced. Not sure but you should try. Hope you get good result.

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