Thread and battery consumption

人盡茶涼 提交于 2019-12-05 05:28:54

To answer your question, it depends what you are doing inside the while loop.

If you are not using and waking up any "expensive" components (such as internet, bluetooth, other sensors, and screen), you should be fine. Essentially this is how the OS works in the background anyways and using a Thread is one of the cheapest ways.

Also, if your task is CPU intensive, you would drain the battery as well.

Your service should work fine if you do it right.

Another way would be using Handlers, which will abstract much of the thread managements for you.

Thread.sleep() makes current thread to suspend, which means CPU will be available for other threads or will simply go off. Please also note sleep forces context switch, but you are on the safe side with big sleep interval. So, generally speaking, everything is up to you.

You can use, for example, PowerTutor to make sure your application is properly designed and implemented.

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