java - My Receiver for SCREEN_OFF doesn't get registered with a Service -
I am working on an app for a custom lockscreen and I think a very annoying speed is hit . The thing is, I have a receiver that checks whether the screen is off and launches any activity works with IntentFilter (Intent.ACTION_SCREEN_OFF) and it can not be registered in the manifest. I need to keep this alive, even if the app is closed, and I researched and found that it can be done through my service setup and start through StartService (); This service is working in one of my main activities because I can see it running in Android emulator in Android settings, but the receiver has not been registered.
This is my service (this is a separate class and not an internal class) and it has been started in the manifest:
The public class extends the LockService service {Private Broadcast Receiver LockReceiver; Public IntentFilter Filter; @ Override Public Empty on Create () {Super. Connet (); Filter = new intent filter (intestine_aCANFF); Lockeresver = new lockboardist (); Register receiver (lock receiver, filter); } @ Override Public Ink on the Internet (Intentional intent, int flag, int start id) {Return Service. START_STICKY; } @ Override public ibindor on bind (intent to intent) {return tap; } @ Override public empty onestoy () {unregistered receiver (lock receiver); Super.onDestroy (); } Here is my broadcast receiver (this is also a separate category and is not an internal category):
Public class lockbreadcast expands Broadcast receiver {@Override Public reception at zero (reference reference, intent of intent) {intent lock = new intention (context, lock class); Context.startActivity (lock); } If I register lockbodcast in my activity, then it works, but only if my app is in the foreground.
I appreciate any insights to this problem. I have gone through many websites and even posted on the stack overflow and some people got to do this work Is nothing, while nothing.
The above code already works for some people but it does not work for me. Any help would be greatly appreciated.
This should work, please make sure that you have not left any of your activity "Receiver Unheard "Code .onDestory () / onStop () method.
Comments
Post a Comment