Reputation: 2398
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?
Upvotes: 4
Views: 3048
Reputation: 22647
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,
android.intent.action.BOOT_COMPLETED
and use permission,
android.permission.RECEIVE_BOOT_COMPLETED
and make sure your receiver has permission,
android.permission.RECEIVE_BOOT_COMPLETED
Like this,
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
...
<receiver ... android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter>
</receiver>
Upvotes: 7