Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/227.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Intent.ACTION屏幕关闭,Intent.ACTION用户演示如何注册_Android - Fatal编程技术网

Android Intent.ACTION屏幕关闭,Intent.ACTION用户演示如何注册

Android Intent.ACTION屏幕关闭,Intent.ACTION用户演示如何注册,android,Android,在我的主要活动中 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 in

在我的主要活动中

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();


无法在AndroidManifest中注册,但只能以编程方式注册。我能做什么?我不想使用服务,因为如果服务整天运行,这对电池不好。解决办法是什么?如何使用此接收器?

您不能从android清单文件注册这些接收器。根本不支持。唯一的方法是长时间运行服务,并在服务中注册这些接收器。所以如果你真的想用

ACTION_SCREEN_ON 


然后您必须使用服务

是的,这对性能有害,运行服务会消耗更多电池。即使我是在这些接收器的基础上开发应用程序的,并检查了所有的可能性,但什么都没有。谢谢你的帮助。如果这是唯一的可能性,我会接受它:D。
ACTION_SCREEN_ON 
ACTION_SCREEN_ON 
ACTION_SCREEN_OFF