What's the best way to have a status bar notification persist when the phone is turned off and on again? The only solution I can think of is to create the notification in a Service which starts in response to the BOOT_COMPLETED_ACTION
Intent.
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
For raising a
Notification
, you can probably get by with just doing it in theBOOT_COMPLETED_ACTION
BroadcastReceiver
, rather than delegating it to a service. However, I agree, this is the only way to do it AFAIK.Just be sure you do not irritate your users by doing this. Most people expect a relatively clean slate when they reboot their phone. Android assumes that notifications are no longer relevant with a reboot, which is why they do not persist.
So, for example, suppose you were writing an email client, and you use notifications to let the user know about unread messages. The answer should not be "redisplay the unread-message notification after a reboot". The answer should be "check for unread messages after a reboot, and raise the notification if there are unread messages". This way, if there are no unread messages (e.g., user had the phone off for a while and took care of their email on their PC or tablet), they do not get a spurious notification.