I start a Service in Background with WakeLock and after work I stop the service and release the WakeLock. But I don’t know the correct order. It works fine but I always get the Error:
10-13 14:48:23.320: A/PowerManager(20951): WakeLock finalized while still held: AppService
Following is my code snippset:
PowerManager pm = (PowerManager)getApplicationContext().getSystemService(Context.POWER_SERVICE);
WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG);
wl.acquire();
After work done, stop everything, but in which order:
stopForeground(true);
wl.release();
stopSelf();
You don’t need to call stopForeground since you’re calling stopSelf right after it. That could be the problem. Without seeing where you’re holding the Wakelock object that’s my best guess. You are correct in calling release before stopSelf though.