Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android wake lock force close

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?

like image 304
Tom Avatar asked Jun 14 '09 16:06

Tom


Video Answer


1 Answers

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

like image 158
snctln Avatar answered Sep 18 '22 14:09

snctln