我从Activity onCreate执行此代码。它会创建一条通知消息。我的问题是:
当活动被销毁时,我是否需要取消注册通知?我的意思是我们在那里传递一个上下文,据我所知,当活动被破坏时通知会停留,这可能会导致内存泄漏。在NotificatuonManagerCompat类中,上下文保持变量。
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this, CHANNEL_ID);
mBuilder.setContentTitle("Picture Download")
.setContentText("Download in progress")
.setSmallIcon(R.drawable.ic_notification)
.setPriority(NotificationCompat.PRIORITY_LOW);
int PROGRESS_MAX = 100;
int PROGRESS_CURRENT = 0;
mBuilder.setProgress(PROGRESS_MAX, PROGRESS_CURRENT, false);
notificationManager.notify(notificationId, mBuilder.build())