How to properly clear all notification once clicked?

前端 未结 2 1333
春和景丽
春和景丽 2021-01-07 17:22

I send a few notification on the notification bar, i wanted to clear all of it when one of the notification is clicked. For now I clear one by one by using Flag. I know

相关标签:
2条回答
  • 2021-01-07 17:28

    You should use a pending intent that sends a broadcast and then put in place a broadcast receiver that will cancel all your notifications. It is best to memorize all notifications IDs and delete them one by one.

    0 讨论(0)
  • 2021-01-07 17:38

    My solution is to call it at onResume().

    @Override
    protected void onResume() {
    super.onResume();
    
    // Clear all notification
    NotificationManager nMgr = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nMgr.cancelAll();
    } 
    
    0 讨论(0)
提交回复
热议问题