android - NotificationManager 的内存泄漏
问题描述
我从 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())
解决方案
推荐阅读
- html - 为什么顺风中的响应式网格不在物理设备上工作,而是在响应式设计模式下工作?
- angular - 设置角度 ngrx 时出错,动作参数不兼容
- android - 无法在 Android 中使用 EXIF 从图像媒体中提取位置(纬度、经度)坐标
- r - 向贝叶斯变化点图添加次要刻度线
- jquery - 添加每个按钮的 DOM 数据属性
- java - 发出ajax请求时刷新Wicket页面
- javascript - html中的按钮onclick已停止工作
- c# - 如何在控制台中连续打印一些随机数?
- javascript - 使用 Tampermonkey/greasemonkey 编辑扩展元素
- javascript - 使用 javascript 添加 div onclick