I have created a broadcast receiver to manage these events (ACTION_SCREEN_ON, ACTION_SCREEN_OFF and ACTION_USER_PRESENT). I register my broadcast receiver like this in my main activity
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_ON);
filter.addAction(Intent.ACTION_SCREEN_OFF);
filter.addAction(Intent.ACTION_USER_PRESENT);
mReceiver = new UnlockReceiver();
registerReceiver(mReceiver, filter);
My problem is that the UnlockReceiver doesn't receive after my app is killed (when I swype it from app selector). I have this problem because these broadcast can't be declared on Manifest I've tried solve it using Service and AlarmManager. How can I solve it?
you dynamically register the broadcast receiver in the activity, that's why it doesn't work.
Declaring it statically in manifest will work, but that's not your case.
I have a workground, and it's up to you to decide to use it or not:
Use a sticky service that works always in background, and register your broadcast receiver in the service.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With