In this receiver, I only request a register from the database and trigger a notification.
Do not do database I / O in the main thread of the application.
I read that tracking lock is needed when a service or action is started from the broadcast receiver, but do I need a tracking lock if I want to show only a notification (in the notification panel)?
In general, no, you wonβt need the WakeLock from BroadcastReceiver , not even the one that is triggered by the _WAKEUP . AlarmManager guarantees in this case that it will support waking up the device using its own WakeLock .
However, again, in this case, you really do not need to do database I / O in the main thread of the application, and onReceive() is called in the main thread of the application. The correct template here is that you move the "register request from the database and start the notification" to the IntentService launched by your BroadcastReceiver so that the work is done in the background thread. This will require WakeLock , because now you are doing work outside of onReceive() . I have a WakefulIntentService that manages WakeLock for you if you want to use it.
source share