Reputation: 2728
I know there are many similar questions, but I am unable to find the solution for my problem. I am using IntentService in which I am downloading a file. I am showing the downloading in notification. The problem is if I force close the app, the notification stuck there. Is there any way to prevent it?
Upvotes: 1
Views: 2099
Reputation: 11188
public static void CancelNotification(Context ctx, int notifyId) {
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager nMgr = (NotificationManager) ctx
.getSystemService(ns);
nMgr.cancel(notifyId);
}
pass notification id when msg receive .
Upvotes: 1
Reputation: 8153
Based on this post: How to determine if the Android Application was force closed?
It's not possible to detect that app was force killed, hence you don't get callback to remove the notification.
If you have some callback to handle when service is done you can use:
NotificationManager.cancel(int id)
Could be possible to have always running background Service
polling running applications and that way detect that the process was closed/killed and remove notifications.
Upvotes: 0