Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Urgent Error] BannerRecyclerView has Loading and Destroy Error! #641

Open
theoyuncu8 opened this issue Jan 29, 2024 · 2 comments
Open

[Urgent Error] BannerRecyclerView has Loading and Destroy Error! #641

theoyuncu8 opened this issue Jan 29, 2024 · 2 comments

Comments

@theoyuncu8
Copy link

theoyuncu8 commented Jan 29, 2024

I got this working for my recyclerview app but there is a problem. When the Activity opens, a banner ad is loaded every 8 items, and even if you destroy it in the onDestroy method, it does not close! This is a critical bug that needs to be resolved! So even if the activity is terminated, adView is reloaded.
I tried such a method, but it is not correct because clearing the list and terminating the adapter while the elements are loading cannot be the right solution. Please update the method

dest

Link: https://github.com/googleads/googleads-mobile-android-examples/blob/master/java/advanced/BannerRecyclerViewExample/app/src/main/java/com/google/android/gms/example/bannerrecyclerviewexample/MainActivity.java


    @Override
    protected void onResume() {
        super.onResume();
        for (Object item : recyclerViewItems) {
            if (item instanceof AdView) {
                AdView adView = (AdView) item;
                adView.resume();
            }
        }
    }

    @Override
    protected void onPause() {
        super.onPause();
        for (Object item : recyclerViewItems) {
            if (item instanceof AdView) {
                AdView adView = (AdView) item;
                adView.pause();
                Log.e("MainActivity", "PAUSE Banner Ad");
            }
        }
    }

    @Override
    protected void onDestroy() {
        for (Object item : recyclerViewItems) {
            if (item instanceof AdView) {
                AdView adView = (AdView) item;
                adView.destroy();
                Log.e("MainActivity", "DESTROY Banner Ad");
            }
        }
        super.onDestroy();
    }


    private void loadBannerAd(final int index) {
        if (index >= recyclerViewItems.size()) {
            return;
        }

        Object item = recyclerViewItems.get(index);
        if (!(item instanceof AdView adView)) {
            throw new ClassCastException("Expected item at index " + index + " to be a banner ad" + " ad.");
        }

        adView.setAdListener(
                new AdListener() {
                    @Override
                    public void onAdLoaded() {
                        super.onAdLoaded();
                        Log.d("MainActivity", "Loaded Banner Ad");
                        loadBannerAd(index + ITEMS_PER_AD);
                    }

                    @Override
                    public void onAdFailedToLoad(@NonNull LoadAdError loadAdError) {
                        Log.d("MainActivity", "Failed Banner Ad");
                        loadBannerAd(index + ITEMS_PER_AD);
                    }
                });

        adView.loadAd(new AdRequest.Builder().build());
    }

@theoyuncu8 theoyuncu8 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 5, 2024
@theoyuncu8 theoyuncu8 reopened this Feb 10, 2024
@theoyuncu8
Copy link
Author

theoyuncu8 commented Feb 10, 2024

This error still persists. For example, if the size of the entire list is 1000 and an ad needs to be loaded in one of every 10 items, it is necessary to wait approximately 1 minute. However, if the user exits the activity while the ads are loading, the ads will continue to load. Please resolve this critical issue immediately!

@NVentimiglia
Copy link
Member

Chain #646

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants