I'm registering a broadcast receiver that will be activated when the screen is turned off. The receiver performs a short, synchronous operation in OnReceive. This operation must happen in my app before the device sleeps.
My question: do I need to acquire a wakelock here, or is it guaranteed that Android will let my receiver finish the OnReceive method? My code takes a few milliseconds to run, but let's say it takes 1 second for the sake of discussion.
I'm using this code to register the receiver:
BroadcastReceiver receiver = new MyReceiver();
IntentFilter filter = new IntentFilter(Intent.ACTION_SCREEN_OFF);
context.registerReceiver(receiver, filter);
I couldn't find an answer in the documentation or by searching, so I would appreciate any help, thank you!