1

I am working with Facebook's Audience Network in my android app that I am building. My onCreate method codes are,

@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main_activity);

this.facebookAdOneLayout = (RelativeLayout) findViewById(R.id.facebook_ads_one);

loadFacebookBannerAds();

}

And my codes that are loading Facebook ads,

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();

    }

Now, I am also destroying facebook ad by calling destroy() method in onPause, onDestroy and onStop

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

I am also calling all super methods for onPause, onStop and onDestroy after calling Facebook's destroy method. So, when I exit activity by clicking back button, in my android monitor, I am getting an error message saying that,

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()?

So can anyone tell me what to do? Where is the error? I tried a lot to find solution for this but couldn't get anything on web.

Thanks,

Viral Joshi
  • 317
  • 2
  • 15

1 Answers1

1

In the Facebook Audience network changelog, there is a line mentioning a memory leak caused by the internal class LocalBroadcastReceiver in the version 4.16.0 (released on 27 September 2016).

Memory leak caused by LocalBroadcastReceiver holding onto MediaView reference

If you create many MediaViews, the resources used by the instances won't be released correctly, ultimately causing an OutOfMemoryError. From version 4.16.0 , this bug seems to be fixed and I have noticed no memory leaks.

Unfortunately, another problem seem to have appeared in the version 4.16.0. From my experience, the videos in MediaView are not automatically played anymore. Moreover, the control of autoplay has been removed, as we can read from 4.16.0 changelog :

setAutoplay and setAutoplayOnMobile deprecated in MediaView

This remains true for version up to 4.18.0 (inclusive). I was unable to test with version 4.19.0, as it mysteriously makes my app crash during the inflation of a custom View (still trying to figure out why).

Gordak
  • 2,060
  • 22
  • 32