Android Intent.ACTION_SCREEN_OFF and Intent.ACTION_USER_PRESENT how to register it

Activity has leaked IntentReceiver ScreenReceiver that was originally registered here. Are you missing a call to unregisterReceiver()? 

in my main activity

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

and when the application is closed, I get this message.

 ACTION_SCREEN_OFF 

AND

 ACTION_SCREEN_ON 

cannot be registered in AndroidManifest, but only programmatically. What can I do? I do not want to use the Service, because if the service is running all day, it is not good for the battery. What is the solution? How to use these receivers?

+4
source share
1 answer

You cannot register this receiver from the android manifest file. This is not support at all. The only way to do this is through long-running services and registering this receiver inside the service. Therefore, if you really want to use

 ACTION_SCREEN_ON 

and

 ACTION_SCREEN_OFF 

Then you should use the service

+3
source

All Articles