I'm writing code to display notifications to the user at specific times (just like the Google Calendar app).
I hence created :
BroadcastReceiver
that listens to BOOT_COMPLETED
, upon reception it sets an alarm in one minute in order to not overload the device when it is still loading stuff;BroadcastReceiver
that listens to alarms: the first set one minute after BOOT_COMPLETED
, and the next at the next appointment (like in Google Calendar)So, typically:
BOOT_COMPLETED
=> launch alarm with a one minute delayWhich means that the status bar notifications are launched from the BroadcastReceiver
.
I have read in the doc that they should be launched from Activities or Services : https://developer.android.com/guide/topics/ui/notifiers/notifications.html#Basics
I'm asking for best practice here. Should I create a Service
that will be launched by the BroadcastReceiver
, and which only purpose will be to launch the status bar notification? My code is working, I just want to create clean code as suggested by Google.
You can add a Notification
from a BroadcastReceiver
, AFAIK. That should be fairly fast. If StrictMode
complains about it, then it might be worth worrying about -- otherwise, you should be OK.
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