2013-04-16 11 views
4
Activity has leaked IntentReceiver ScreenReceiver that was originally registered here. Are you missing a call to unregisterReceiver()? 
在主要活動

的Android Intent.ACTION_SCREEN_OFF和Intent.ACTION_USER_PRESENT如何註冊

// Register receiver that handles screen on and screen off logic 
final IntentFilter intentScreenfilter = new IntentFilter(Intent.ACTION_SCREEN_ON); 
intentScreenfilter.addAction(Intent.ACTION_SCREEN_OFF); 
intentScreenfilter.addAction(Intent.ACTION_USER_PRESENT); 
screenReceiver = new ScreenReceiver(); 

,當應用程序被關閉,我得到這個消息。

ACTION_SCREEN_OFF 

ACTION_SCREEN_ON 

不能註冊在AndroidManifest但只是編程。我能做什麼?我不想使用服務,因爲如果服務一整天都在運行,這對電池並不好。解決辦法是什麼?如何使用這個接收器?

回答

3

你不能從Android清單文件註冊這些接收器。它根本沒有支持。唯一的辦法是長時間運行服務,並將這些接收器註冊到服務中。所以,如果你真的想用

ACTION_SCREEN_ON 

ACTION_SCREEN_OFF 

然後,你必須使用服務

+0

呵呵但是這是不好的表現是不是? – senzacionale

+0

是的,它對性能不利,運行服務會消耗更多電量。即使我是在這些接收器的基礎上開發應用程序,並檢查了所有可能性,但沒有出現。 – Naga

+1

感謝您的幫助。如果這是唯一的可能性,我會採取它:D。 – senzacionale