PARTIAL_WAKE_LOCK vs SCREEN_DIM_WAKE_LOCK in the download stream

I have a service that launches a download stream that sometimes downloads large files. I realized that as soon as the phone falls asleep, the download flow will slow down significantly, and then stop.

Obvious remedy, wakeles. Therefore, I would think that it would be normal to get partial_wake_lock, just for the processor to handle the load. This does not work, though, with the same behavior, loading slows down and then stops when the screen turns off.

Then I tried screen_dim_wake_lock. This time the screen remained (darkened), and the download continued until full speed, until it was done, wakelock was released, and then the phone slept.

My question is, why can I not continue to work in the stream if I hold partial_wake_lock the same way as during screen_dim_wake_lock? Is there any undocumented behavior regarding the difference between the two? Is it because I may not be working in the user interface thread?

EDIT:

I added wifilock. Wi-Fi doesn't go to bed, but my thread is still dying. If any other process wakes up the system, the download will continue at normal speed and then slow down. If I wake up on the phone, it will continue at a normal speed than at a slow pace when the screen goes blank. It seems that the flow is superimposed on the background by the system. I wonder if I can prevent this.

+7
source share
2 answers

I had the same issue with you with a single service that is constantly loading a large set of URLs. It was best to use screen_dim_wake_lock as you did, and bring your service in the foreground, as described here .

Thus, the screen is always on, so this also happens with your WIFI interface. Otherwise, if you leave the phone inactive for a while, then the screen will turn off, the phone will go into sleep mode, and WIFI will also turn off after 15 minutes!

So, another way is to use partial_wake_lock (only the processor is turned on) and change the settings of your phone so that WIFI is always on (maybe this is similar to the WIFI_LOCK that you get ..):

  • from the main screen, go to the "System" or "Settings" section, and then
  • select Wireless and Networks.
  • select WIFI settings
  • press Menu and select More
  • click Wi-Fi Sleep Policy and change it to Never

Then your service will work even in sleep mode when the screen is off. The only problem here is:

If you lose the WIFI connection for a while, then Android may kill your service because it will be inactive. But if your phone is always connected to a WIFI network with good stability, then everything will work fine.

+1
source

Take a look at the Wifi lock along with a partial lock:

http://developer.android.com/reference/android/net/wifi/WifiManager.WifiLock.html

0
source

All Articles