Cancel notification on remove application from multitask panel

前端 未结 7 1744
北恋
北恋 2020-11-27 14:15

I manage an ONGOING notification from my application (not from a service).

When I kill application from task manager with \"End\" button, no

7条回答
  •  情深已故
    2020-11-27 15:00

    The ability to swipe apps out of the recent apps list is introduced in Ice Cream Sandwich (API-14).

    With the same Android version, we received a special method "onTaskRemoved()" in "android.app.Service". It is get invoked when app is removed from recent apps list.

    So, just override "onTaskRemoved()" method to achieve your requirements if you are having any service running.

    E.g.:

    @Override
    public void onTaskRemoved(Intent rootIntent) {
        NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
        mNotificationManager.cancel(NOTIFICATION_ID);
    }
    

    Or simply write & start special service to manage the same.

提交回复
热议问题