为什么Android Facebook受众网络在调用destroy方法后仍在泄漏活动



我正在与Facebook的观众网络在我的android应用程序,我正在建设。我的onCreate方法代码是,

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);
this.facebookAdOneLayout = (RelativeLayout) findViewById(R.id.facebook_ads_one);
loadFacebookBannerAds();
}

加载Facebook广告的代码,

private void loadFacebookBannerAds() {
        this.facebookAdOne = new com.facebook.ads.AdView(this, getString(R.string.fb_ad_id_one),
                AdSize.BANNER_320_50);

        //This setting is to load test ads served by Facebook. Just delete whole line in live app
        AdSettings.addTestDevice("TestDeviceID");
        this.facebookAdOneLayout.addView(this.facebookAdOne);
        this.facebookAdOne.loadAd();
    }

现在,我也销毁facebook广告通过调用destroy()方法在onPause, onDestroy和onStop

if (facebookAdOne != null) {
            facebookAdOne.destroy();
        }

在调用Facebook的destroy方法后,我还调用了onPause, onStop和onDestroy的所有超级方法。因此,当我通过点击后退按钮退出活动时,在我的android监视器中,我得到一个错误消息说,

Activity test.app.MainActivity has leaked IntentReceiver com.facebook.ads.internal.h$c@94eb1f that was originally registered here. Are you missing a call to unregisterReceiver()?

android.app.IntentReceiverLeaked: Activity test.app.MainActivity has leaked IntentReceiver com.facebook.ads.internal.h$c@94eb1f that was originally registered here. Are you missing a call to unregisterReceiver()?

谁能告诉我该怎么做?错误在哪里?我试了很多办法来解决这个问题,但在网上找不到任何东西。

谢谢,

在Facebook Audience网络更新日志中,有一行提到4.16.0版本(2016年9月27日发布)中由内部类LocalBroadcastReceiver引起的内存泄漏。

LocalBroadcastReceiver占用MediaView导致内存泄漏参考

如果你创建了很多mediaview,实例所使用的资源将不会被正确释放,最终导致OutOfMemoryError。从4.16.0版本开始,这个错误似乎被修复了,我注意到没有内存泄漏。

不幸的是,另一个问题似乎出现在4.16.0版本。根据我的经验,MediaView中的视频不再自动播放了。此外,自动播放的控制已经被删除,我们可以从4.16.0的更新日志中读到:

setAutoplay和setAutoplayOnMobile在MediaView中已弃用

对于4.18.0(含)之前的版本仍然如此。我无法使用4.19.0版本进行测试,因为它在自定义视图膨胀期间神秘地使我的应用程序崩溃(仍在试图找出原因)。

最新更新