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

[ad_mob] dispose does not dispose BannerAd if called before being loaded on Android #96

Closed
alextekartik opened this issue Sep 6, 2019 · 6 comments
Labels
plugin: admob type: bug Something isn't working

Comments

@alextekartik
Copy link
Contributor

alextekartik commented Sep 6, 2019

Describe the bug
On Android, If BannerAd.dispose() is called quickly after the BannerAd.show() is called, the banner might still be shown and can never be hidden

To Reproduce
It is easier to reproduce by code (simple call show() then dispose()) but the example app should be enough
Steps to reproduce the behavior:

  1. Build and run (flutter run) AdMob example app, can be on an emulator using test ads (although easier to reproduce on real device)
  2. Tap 'SHOW BANNER' then 'REMOVE BANNER' right away (the more the speed is like a double click, the more it might show the issue)
  3. If you did not manage to tap 'REMOVE BANNER' before the ad appears, the ad will be hidden correctly. Otherwise the ad might still appear (a little bit later - once loaded) and 'REMOVE BANNER' will never remove it.
  4. It might have worked as expected, otherwise try again multiple times, you might get to a point where 'REMOVE BANNER' can no longer hide the ad.

Expected behavior
Calling dispose() should dispose the ad and prevent it from being shown later.

Additional context
There seems to be an edge case condition in Android state machine where the ad view can be inserted in the tree once loaded - although adView.destroy() [java] has been called - but maybe that is not enough, some Android aps also hide the view (maybe add a new destroyed state to handle if the ad gets loaded later to prevent adding the child adView).

The workaround I have currently is that I wait (30s) for any event (loaded/load failure) before calling dispose on the dart land.

I have not tested on iOS (or at least not seen such issue)

If needed, I can work on a fix (just add this new destroyed state on Android) and submit a PR, let me know

@alextekartik alextekartik added the type: bug Something isn't working label Sep 6, 2019
@LouisParkin
Copy link

By managing the loaded state of the ads, I manage to get it to work correctly on Android, but on iOS, calling dispose appears to pop banners off a stack, rather than popping the one for which a reference is provided.

@hesyar
Copy link

hesyar commented Apr 21, 2020

@LouisParkin how did you solve this by managing the state?

@LouisParkin
Copy link

LouisParkin commented Apr 22, 2020

@hesyar I posted one of my dart files here: https://gist.github.com/LouisParkin/9e669b533f404c940d256fdb9af87afe
^ This one has the implementation of the banner
And another here https://gist.github.com/LouisParkin/3f16687443c3b1e15507648ccf84161c
^This one has the state-managed disposal of a banner.

@hesyar
Copy link

hesyar commented Apr 22, 2020

@LouisParkin thanks a lot ;) I will check this in the evening

@blasten
Copy link
Contributor

blasten commented May 15, 2020

Another race condition: #669

@russellwheatley
Copy link
Member

The firebase_admob plugin will be deprecated in April 2021 in favor of Google Mobile Ads SDK for Flutter.
Google Mobile Ads SDK for Flutter is a new Flutter plugin that supports more Ads formats than firebase_admob does. Google Mobile Ads SDK for Flutter currently supports loading and displaying banner, interstitial (full-screen), native ads, and rewarded video ads across AdMob and AdManager. It also supports displaying banner and native ads as Widgets as opposed to being overlayed over all app content.
We're now recommending projects currently using firebase_admob migrate to Google Mobile Ads SDK for Flutter following the instructions outlined here.
Issues with migrating or with using the new package should now be raised over on the Google Mobile Ads SDK for Flutter repository.

@firebase firebase locked and limited conversation to collaborators Apr 19, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
plugin: admob type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants