I have a service that spawns a download thread that downloads sometimes large files. I realized that as soon as the phone went to sleep, the download thread would slow down significantly, then stop.
The obvious remedy, a wakelock. So I would think that it would be ok to acquire a partial_wake_lock, just to keep the cpu processing the download. That doesn't work though, same behavior, the download slows and then stops when the screen turns off.
Then I tried a screen_dim_wake_lock. This time, screen stayed on (dimmed), and the download kept going at fullspeed until it was done, wakelock released, and then phone slept.
My question is, why can't I keep my thread running when holding a partial_wake_lock the same as it does during a screen_dim_wake_lock? Is there some undocumented behavior about the difference between these 2? Is it because I am not running on the UI thread perhaps?
EDIT:
I added a wifilock. The wifi doesn't go to sleep, but my thread still dies. If some other process wakes up the system, the download will continue at normal speed, then slow down again. If I wake up the phone, it will continue at normal speed than will slow down once again when the screen goes out. It seems as though the thread is getting pushed into the background by the system. I wonder if I can prevent that.