0

I have Implemented Ironsouce banner in all activity with below method but its only work in main activity and in other activities show error message

 API: Multiple calls to init without ad units are not allowed  API: L a - can't load banner - loadBanner already called and still in progress  API: L a - can't load banner - loadBanner already called and still in progress

    IronSource.init(this, "APP_ID");
    IronSource.setMetaData("Facebook_IS_CacheFlag","IMAGE");
    final FrameLayout bannerContainer = findViewById(R.id.adview);
    IronSourceBannerLayout bannerLayout = IronSource.createBanner(this, ISBannerSize.SMART);
    IronSource.loadBanner(bannerLayout, (String) "DefaultBanner");
    FrameLayout.LayoutParams layoutParams = new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,
            FrameLayout.LayoutParams.WRAP_CONTENT);

    bannerContainer.addView(bannerLayout);
    IronSource.loadBanner(bannerLayout);

    IronSource.loadInterstitial();

    IronSource.setInterstitialListener(new InterstitialListener() {
        @Override
        public void onInterstitialAdReady() {
            IronSource.showInterstitial("DefaultInterstitial");
        }

        @Override
        public void onInterstitialAdLoadFailed(IronSourceError ironSourceError) {

        }

        @Override
        public void onInterstitialAdOpened() {

        }

        @Override
        public void onInterstitialAdClosed() {

        }

        @Override
        public void onInterstitialAdShowSucceeded() {

        }

        @Override
        public void onInterstitialAdShowFailed(IronSourceError ironSourceError) {

        }

        @Override
        public void onInterstitialAdClicked() {

        }
    });

1 Answers1

0

If you are moving back and forth form one activity to another than you have to destroy the banner, always destroy banner before loading a new banner,

so while going form activity A to B destroy banner in A than go to B and load the in B.

  IronSource.destroyBanner(banner);

and while coming back form B to A than also destroy in B and again reload the banner in A

you can use onBackPressed to destroy the banner

    public void onBackPressed() {
        super.onBackPressed();
        IronSource.destroyBanner(banner);
        finish();
    }

If there is a backbutton on nav bar

@Override
    public boolean onOptionsItemSelected(MenuItem item) {
        if (item.getItemId() == android.R.id.home) {
            IronSource.destroyBanner(banner);
            finish();
            return true;
        }
        return super.onOptionsItemSelected(item);
    }

this may vary in your case android.R.id.home

Pranoy Sarkar
  • 1,965
  • 14
  • 31