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.