androidnotificationsandroid-serviceandroid-8.0-oreonotificationmanager

How to cancel ongoing notification when app is killed in Oreo?


I'm facing issue in cancelling ongoing notification from notification bar. It's working perfectly on previous versions of android using onTaskremoved() in Service,but not in Oreo. I just need to cancel notification when app is force closed from recent apps. Please let me know if any one have solution for this. Previous versions


Solution

  • UPDATE

    If you force close your app, onDestroy will not be called and you have no option to intercept this action.

    Here and Here are two references about it, you can find much more

    ....................

    Add Those line inside in you service

    @Override
    public void onDestroy() {
        super.onDestroy();
        stopForeground(true);
    
    }