I have googled this non stop today and could not find anything. My scenario is the following:
I have an Android app that auto replies to incoming messages. I have
If your notifications are handled by a service and target API is 14 or higher then you have an opportunity to cancel notifications in overriden "void onTaskRemoved(Intent rootIntent)" method.
Have you try .setAutoCancel(true)
in your notification and in your manifest add android:launchMode="singleTask"
, android;clearTaskOnLauch="true"
in the activity xml
your notification icon should clear the moment you press it on the notification bar.
As far as i can tell you are creating a new NotificationManager object to create the notification and a different notificationManager object to cancel the notifications. You should be using the same object. The way you are doing it, you are not firing any notification with the object in the notifDestroy(), hence probably it doesnt clear the notification for you.
The method that I used to kill the processes when I swipe apps from the recents is: in the first activity of the app, in the method OnDestroy I write that "the process have to kill". In this way I call the OnDestroy method of the process and so the process really kills himself and the notification is removed. Specifically, in the first Activity:
@Override
public void onDestroy() {
super.onDestroy();
Intent intent = new Intent();
intent.setAction(Service.MY_ACTION_FROMACTIVITY);
intent.putExtra(Service.CMD, Service.CMD_STOP);
sendBroadcast(intent);
}
So the following operations are:
@Override
public void onDestroy() {
// TODO Auto-generated method stub
barNotification.cancel(NOTIFICATION);
sensorManager.unregisterListener(this);
this.unregisterReceiver(myServiceReceiver);
super.onDestroy();
}
I hope that I can help you.