2012-10-13 101 views
1

我使用WakeLock在後臺啓動服務,下班後停止服務並釋放WakeLock。但我不知道正確的順序。它工作正常,但我總是得到錯誤:使用WAKE_LOCK停止服務

10-13 14:48:23.320: A/PowerManager(20951): WakeLock finalized while still held: AppService 

以下是我的代碼snippset:

PowerManager pm = (PowerManager)getApplicationContext().getSystemService(Context.POWER_SERVICE); 
WakeLock wl = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, TAG); 

wl.acquire(); 

工作完成後,停止一切,但以何種順序:

stopForeground(true); 
wl.release();     
stopSelf(); 

回答

1

你因爲你在它之後調用stopSelf,所以不需要調用stopForeground。這可能是問題所在。沒有看到你拿着Wakelock物體的位置,這是我最好的猜測。儘管如此,您在stopSelf之前調用發佈版是正確的。

+0

感謝它的工作! – user1390816