0

My application is running a service . What i want is that , I want screen to awake till my service running in background. I have used this

PowerManager pm;
PowerManager.WakeLock wakeLock;

pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK,"x2_wakelook");
wakeLock.acquire();
wakeLock.release();

But this code does not work till life span of my service. Screen goes to sleep as soon as i get out of my application. Any help !

Ahmed
  • 814
  • 2
  • 19
  • 38

1 Answers1

0

But this code does not work till life span of my service.

You specifically are releasing the WakeLock immediately after acquiring it. You need to move the release() call to the point where you want the WakeLock to be released.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks for reply , I put whole code here that i am using. I know that where i have to release lock at end of my service. – Ahmed Oct 09 '12 at 22:33