0

I need to cancel the notification of my application when my application terminates (when it is removed from the taskmanager). To clear the notification I wrote this method.

public void deleteNotification(){
    NotificationManager notifManager = (NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
    notifManager.cancelAll();
}

I put it in OnDestroy but the notification remains active and is not extinguished. I know that Android is not always immediately brings the event, how can I do? thank you in advance

Davide
  • 127
  • 1
  • 2
  • 12
  • Have you tried calling the method in onStop()? – M0rty Aug 18 '16 at 20:23
  • I can't use onStop beaucase i want cancel notification only when the app is closed and not when it is put in background – Davide Aug 19 '16 at 07:35
  • Ok, maybe you could check if the application is in onPause() (In the background) and if the application is onPause() don't run the notification method else do run it. – M0rty Aug 19 '16 at 07:44
  • The problem is that the method onPause is used to create the notification. Take example from Android timer, when it put in background the notification appears, whene it is closed from taskmanager the notification disappears. I have to do the same thing. – Davide Aug 19 '16 at 07:49
  • You could try this http://stackoverflow.com/a/26217757/3945848 – M0rty Aug 19 '16 at 08:27
  • The method that you suggested can not work beaucase the onStop() is also called when the activity is put into backgrund, have you other solutions? – Davide Aug 19 '16 at 10:35

0 Answers0