Question

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?

Was it helpful?

Solution

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...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top