Correct Way to Register for SCREEN_OFF and SCREEN_ON events
So I recently discovered that SCREEN_OFF and SCREEN_ON actions can't be
received by registering them in an application's manifest (no idea why),
which requires me to register programmatically instead.
However, I'm not sure where would be the best place to do this? Ideally I
would like to just register by BroadcastReceiver to handle these events
just like I handle everything else, but where should I actually perform
the registration? Is there another action I could register to that would
be a better place for me to perform such setup actions?
Currently I'm doing this by triggering a broadcast in the main activity
when opened, that the receiver can then receive, and attempt to register
itself for screen events. But this will only work if the application has
been run at least once.
No comments:
Post a Comment