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

        }
    });

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

0

When starting a new activity call IronSource.destroyBanner(banner);

  • In mainActivity override OnResume and add if(banner.isDestroyed()) Like this:

protected void onResume() {
        super.onResume();
        IronSource.onResume(this);
        if(banner.isDestroyed())
            SecondBannerInit();
    }

  • SecondBannerInit:

 private void SecondBannerInit(){

        banner = IronSource.createBanner(MainActivity.this, ISBannerSize.BANNER);
        bannerContainer.addView(banner, 0);

        IronSource.loadBanner(banner);
        banner.setLevelPlayBannerListener(new LevelPlayBannerListener() {
            // Invoked each time a banner was loaded. Either on refresh, or manual load.
            //  AdInfo parameter includes information about the loaded ad
            @Override
            public void onAdLoaded(AdInfo adInfo) {Log.d(TAG, "Banner Ad Loaded");}
            // Invoked when the banner loading process has failed.
            //  This callback will be sent both for manual load and refreshed banner failures.
            @Override
            public void onAdLoadFailed(IronSourceError error) {Log.d(TAG, "Banner Ad Failed " + error.toString());}
            // Invoked when end user clicks on the banner ad
            @Override
            public void onAdClicked(AdInfo adInfo) {}
            // Notifies the presentation of a full screen content following user click
            @Override
            public void onAdScreenPresented(AdInfo adInfo) {}
            // Notifies the presented screen has been dismissed
            @Override
            public void onAdScreenDismissed(AdInfo adInfo) {}
            //Invoked when the user left the app
            @Override
            public void onAdLeftApplication(AdInfo adInfo) {}

        });
    }

don't forget to override OnBackPressed() Method in the SecondActivity and Destroy the banner.

Happy Coding.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.