AndriousSolutions / ads

Other
58 stars 11 forks source link

Issue with internal navigation -- Ad already instantiated #25

Closed rodstafford closed 4 years ago

rodstafford commented 4 years ago

I have an app with several pages, only one page uses ads and it has a button that when clicked shows a video. As long as I remain on that page, there are no error messages and it works fine and I can see another video ads if the button is clicked again, but when I navigate to another page and then navigate back, I no longer can get ads, and I get this message logged: 'An Ads class is already instantiated!'. Yet, if I navigate away from the app (the app lifecycle enters a paused state) and it goes in the background, it works correctly when it resumes and I can continue to see video ads until I go to another page within the app.

I do not understand why this is occurring (I'm kinda new to this). My question is, is this behavior I have to live with, or is there something I can do so that I can navigate within the app and still see a video ad.

Andrious commented 4 years ago

Excellent, Rob!

Good of you to contact me. I've yet to receive such an issue, but (you said yourself) you're kinda new to this. And that's ok! Here we go.

Possibly, it's a matter of simply 'wrapping' your Ads class and using that 'static' reference again when you come back to that page. Here you go, use this bit of code, AppAds.dart.

That error message you found is by design. You see, working with Google Ads is an 'expense' process (memory cycles and RAM). The message is telling you to use the 'instance' you already have in memory. It's explained a little bit in the Ads package page, There Must Only Be One!.

It may be hard for beginners to get their head around, that's why I even wrote an free article about it, My Code’s Not Good! Know Why?

Greg