tags:

views:

118

answers:

2
+3  Q: 

Android WakeLock

Hey guys!

I have a problem with acquiring a WakeLock. It seems not to work. I am trying to acquire a FULL_WAKE_LOCK but neither the display gets enabled nor is my app able to perform tasks.

I am using the following permission: android.permission.WAKE_LOCK

My acquire code looks like this:

PowerManager pm = (PowerManager) getBaseContext().getSystemService(Context.POWER_SERVICE);
wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK|PowerManager.ACQUIRE_CAUSES_WAKEUP, "My Tag");
wl.acquire();

What am i doing wrong?

Edit: Added another flag ACQUIRE_CAUSES_WAKEUP ... but no changes in behavior

Edit2: All i am trying to do is, to play music and to wake my device up upon a certain event. The music is working perfectrly but the device stays black.

+1  A: 

Where are you acquiring the wake lock? You will need to acquire it in the receiver of the intent, not in the service/activity that your intent starts.

Nic Strong
i am acquiring it in an anctivity because i have an activity set as receiver
Coxer
I am not sure I understand. An Activity cannot be a BroadcastReceiver as the BroadcastReceiver is an abstract class not an interface (no multiple inheritance in Java). Do you mean you have a private static BroadcastReceiver on the activity class?All I am saying is you must take the wake lock in onReceive() in the BroadcastReceiver not in onCreate() of the Activity that you start from the service.
Nic Strong
A: 

I get same problem :got RTC_WAKEUP event, play music, screen off and then device back to Sleep state again. I do acquire FULL WAKE LOCK in onReceive() in the BroadcastReceiver. What a damn strange bug. Is anybody has an idea about that ?

TungBS