views:

1720

answers:

1

Hello I am trying to implement a wake lock for an application.

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

It seems to force close when defining the PowerManager shown in the code above. Whats going wrong?

+1  A: 

Are you receiving this force close when running the code in the emulator on an actual device?

Have you set breakpoints in eclipse to verify that the getSystemService() call is what is causing the problem?

In eclipse when the force close occurs does LogCat say anything about it?

Did you set

<uses-permission android:name="android.permission.WAKE_LOCK" />

in the manifest?

You could also try defining pm as final:

final PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);

Let me know if any of this helps...

snctln
Tried the "final" with no change :( and the correct permission is in place.I have had a look in the logcat but tbh I'm not to great a decoding it...
Tom
Does anything show up in Red in LogCat at the time of the force close? If so copy and paste the red lines here and I can try to help decipher it
snctln
Thanks for your help. Someone @ google groups fixed it. http://groups.google.com/group/android-developers/browse_thread/thread/38e1510eda011ce6#
Tom