【内存泄漏Bug】registerReceiver Are you missing a call to unregisterReceiver()异常分析及解决

【内存泄漏Bug】registerReceiver Are you missing a call to unregisterReceiver()异常分析及解决

码农世界 2024-05-28 前端 82 次浏览 0个评论

问题描述

开发一款WIFI管理APP,再wifi列表页面注册了广播监听,监听网络变化,页面是常驻内存的,跳转到其他app或者其他页面的时候,此页面存在被系统销毁的可能。

    android.app.IntentReceiverLeaked: Activity com.xx.activity.FridgeMainActivity has leaked IntentReceiver com.xx.sifiview.WifiConnector$WifiConnectReceiver@46e4de0 that was originally registered here.?
        at android.app.LoadedApk$ReceiverDispatcher.(LoadedApk.java:1351)
        at android.app.LoadedApk.getReceiverDispatcher(LoadedApk.java:1132)
        at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1422)
        at android.app.ContextImpl.(ContextImpl.java:1395)
        at android.app.ContextImpl.registerReceiver(ContextImpl.java:1383)
        at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:609)
        at com.xx.sifiview.WifiConnector.registWifiConnectReceiver(WifiConnector.java:127)
        at com.xx.sifiview.WifiConnector.connect(WifiConnector.java:84)
        at com.xx.sifiview.SettingWifiView.connect(SettingWifiView.java:286)
        at com.xx.sifiview.SettingWifiView.onItemClick(SettingWifiView.java:260)
        at com.chad.library.adapter.base.BaseQuickAdapter.setOnItemClick(BaseQuickAdapter.java:987)
        at com.chad.library.adapter.base.BaseQuickAdapter$5.onClick(BaseQuickAdapter.java:966)
        at android.view.View.performClick(View.java:6300)

问题分析

页面回退之后,广播忘记反注册

问题解决

页面销毁调用反注册广播

转载请注明来自码农世界,本文标题:《【内存泄漏Bug】registerReceiver Are you missing a call to unregisterReceiver()异常分析及解决》

百度分享代码,如果开启HTTPS请参考李洋个人博客
每一天,每一秒,你所做的决定都会改变你的人生!

发表评论

快捷回复:

评论列表 (暂无评论,82人围观)参与讨论

还没有评论,来说两句吧...

Top