views:

38

answers:

1

Hey all,

I have a signal that puts my app to sleep for a given number of minutes (using AlarmManager) and then wakes it back up.

Everything is working except the screen doesn't ever come on. I'm using a wakelock like so from a BroadcastReceiver class:

     KeyguardManager key = (KeyguardManager) context.getSystemService(Context.KEYGUARD_SERVICE);
     KeyguardLock lock = key.newKeyguardLock(TAG);
     lock.disableKeyguard();
     Log.v(TAG, "alarm: disabled keyguard.");

     PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
     gpsMain.wl = pm.newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK, TAG);
     gpsMain.wl.acquire();
     Log.v(TAG, "alarm: acquired wakelock");

     Intent i = new Intent();
     i.setAction(CUSTOM_INTENT);
     context.sendBroadcast(i);

I then release the wakelock when I'm sure that my app is up and running and connected again. However, the screen never comes on! The app only actually comes back to life when I hit the power button to wake up the screen manually.

I'm developing on an HTC Hero. Any assistance would be GREATLY appreciated..

A: 

You need to use the ACQUIRE_CAUSES_WAKEUP flag.

CommonsWare
Yes, I changed my lock to use PowerManager.ACQUIRE_CAUSES_WAKEUP in addition to FULL_WAKE_LOCK. I'm also using AlarmManager.RTC_WAKEUP, which is supposed to wake up the phone when the alarm goes off. Still no luck though...
Tom G
@Tom G: Hmmmm...that's odd. I just had an email exchange this week with somebody on the `android-developers` list, who said that this worked for him. I am a bit confused about your symptoms: is it that your code runs but the screen does not light up, or is your code not running at all?
CommonsWare
So, I think I solved it. I was acquiring the wakelock in the broadcastreceiver that the alarm calls, but I was releasing it back in my main thread. I moved the release to teh end of the onReceive function and now it seems to be working.
Tom G
@Tom G: You may have made the same mistake I did the first time I used `WakeLocks`. I looked at the tag to be passed into `newWakeLock()` and thought it was a key -- the same app requesting the same key twice would get the same `WakeLock` object. That's not how it works. That's just a name for logging purposes. To pass `WakeLocks` between components, the only option right now is (sigh) mutable static data members. For example, my `WakefulIntentService` supports this: http://github.com/commonsguy/cwac-wakeful
CommonsWare