简体   繁体   中英

Android device sleeping issue

I have a little issue when I set option for device not sleeping. I'm connecting to web server and downloading data and when I'm doing this I need the device stay awake. I'm using this in this way :

1.In my Synchronization class when I start a connection to a web server I set this :

PowerManager powerMan = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl = powerMan.newWakeLock(PowerManager.FULL_WAKE_LOCK, "My Tag");
wl.acquire();

and onDestroy() method in this activity I set :

wl.release();

But it seems that after this the device is not sleeping even if I close my application. Is there something that I'm doing wrong. Thanks in advance!

Try to use this instead of WakeLock Manager :

getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

this will keep your screen on and you can remove that option by doing his :

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);

This should help.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM