Activity has leaked IntentReceiver ScreenReceiver that was originally registered here. Are you missing a call to unregisterReceiver()?
在主要活动中我有
// 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
AND
ACTION_SCREEN_ON
无法在AndroidManifest中注册,只能以编程方式注册。我能做什么?我不想使用服务,因为如果服务全天运行,这对电池不利。解决办法是什么?如何使用这个接收器?
答案 0 :(得分:2)
您无法从Android清单文件中注册这些接收器。它根本不支持。唯一的方法是长时间运行服务并在服务中注册这些接收器。所以,如果你真的想使用
ACTION_SCREEN_ON
和
ACTION_SCREEN_OFF
然后你必须使用服务