My app works But when it goes to Stop service it just crashes because wakelock "DoNotSleep" state so I will be glad to hear some advices. thats my logcat:
05-15 00:41:06.925: E/AndroidRuntime(4471): FATAL EXCEPTION: main
05-15 00:41:06.925: E/AndroidRuntime(4471): java.lang.RuntimeException: Unable to stop service com.example.iw84u.GpsTracker@40812c40: java.lang.RuntimeException: WakeLock under-locked DoNotSleep
05-15 00:41:06.925: E/AndroidRuntime(4471): at android.app.ActivityThread.handleStopService(ActivityThread.java:2086)
05-15 00:41:06.925: E/AndroidRuntime(4471): at android.app.ActivityThread.access$2900(ActivityThread.java:117)
05-15 00:41:06.925: E/AndroidRuntime(4471): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1001)
05-15 00:41:06.925: E/AndroidRuntime(4471): at android.os.Handler.dispatchMessage(Handler.java:99)
05-15 00:41:06.925: E/AndroidRuntime(4471): at android.os.Looper.loop(Looper.java:130)
05-15 00:41:06.925: E/AndroidRuntime(4471): at android.app.ActivityThread.main(ActivityThread.java:3691)
05-15 00:41:06.925: E/AndroidRuntime(4471): at java.lang.reflect.Method.invokeNative(Native Method)
05-15 00:41:06.925: E/AndroidRuntime(4471): at java.lang.reflect.Method.invoke(Method.java:507)
05-15 00:41:06.925: E/AndroidRuntime(4471): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:907)
05-15 00:41:06.925: E/AndroidRuntime(4471): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:665)
05-15 00:41:06.925: E/AndroidRuntime(4471): at dalvik.system.NativeStart.main(Native Method)
05-15 00:41:06.925: E/AndroidRuntime(4471): Caused by: java.lang.RuntimeException: WakeLock under-locked DoNotSleep
05-15 00:41:06.925: E/AndroidRuntime(4471): at android.os.PowerManager$WakeLock.release(PowerManager.java:311)
05-15 00:41:06.925: E/AndroidRuntime(4471): at android.os.PowerManager$WakeLock.release(PowerManager.java:286)
05-15 00:41:06.925: E/AndroidRuntime(4471): at com.example.iw84u.GpsTracker.onDestroy(GpsTracker.java:126)
05-15 00:41:06.925: E/AndroidRuntime(4471): at android.app.ActivityThread.handleStopService(ActivityThread.java:2069)
05-15 00:41:06.925: E/AndroidRuntime(4471): ... 10 more
And in my code here in the service wakelock exists:
public void onCreate() {
super.onCreate();
PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "DoNotSleep");
}
public void onDestroy() {
// TODO Auto-generated method stub
super.onDestroy();
wakeLock.release();
}
public int onStartCommand(Intent intent, int flags, int startId) {
// Here there's some calculations with the intent
return START_REDELIVER_INTENT;
}
private void UpdateWithNewLocation(final Location loc) {
//Some commands and then .....
stopSelf();
}
What can I do with that crash of wakelock? thanks.