Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Thread and battery consumption

I am working on app that check some of the status of phone every 5 seconds. I done it that:

Thread checking = new Thread() {
    public void run(){
        while( <<some status>> ) {
            <<checkstatus and do something>>
            Thread.sleep(5000);
        }
    }
}

This is bad for the battery? How can I do it in the other way? Service stop working after couple seconds.

like image 860
Mateusz Kaflowski Avatar asked Oct 08 '12 21:10

Mateusz Kaflowski


People also ask

Which theme consume more battery?

Does a light theme really consume more battery? Yes. Overall the lighter the screen the more energy it will use, as screens emit light meaning they must generate the proper wave lengths of light to create a colour. Since white is all the colours combined a white screen will require more power to run.

Does double tap to sleep consume battery?

Senior Member. I don't notice any further battery consumption using this feature.

How do you calculate battery usage?

Multiplying the average or nominal battery voltage times the battery capacity in amp-hours gives you an estimate of how many watt-hours the battery contains.

Why screen is consuming too much battery?

There are too many apps running in the background. The screen is too bright. The screen is staying on too long before going to sleep. The phone doesn't have service.


1 Answers

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.

like image 161
Edison Avatar answered Sep 23 '22 04:09

Edison