kamal kamal - 1 year ago 71
Android Question

Notification gets disappeared when phone is rebooted

I am working on alarms and making an app for task reminder.
I am showing notification at scheduled time by user.
But when alarm rings , notification appears . Then I switched off my phone , and again when I switched , on the notification get disappeared(doesnt show the notification).
while in the case of SMS notifiaction(default android implementation) it does not get disappeared until we drag the notification.

I want the same as like sms notification.
What should I do.

Answer Source

Notifications are not persistent across device boots. If they reappear for certain apps, it's because the app is starting on boot and re-creating them.

You should define a receiver that determines if the notification should be present and creates it if necessary, and start this receiver on device boot.

Set its intent filter for,


and use permission,


and make sure your receiver has permission,


Like this,

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<receiver ... android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
    <action android:name="android.intent.action._BOOT_COMPLETED"/>