googleads / googleads-mobile-flutter

A Flutter plugin for the Google Mobile Ads SDK
Apache License 2.0
331 stars 267 forks source link

AdMob banner disappears after reopen the app - Flutter #545

Closed drahmedgabr closed 2 years ago

drahmedgabr commented 2 years ago

Plugin Version

1.2.0

Steps to Reproduce

1- Run App (simple app run audio streams foreground & background) 2- Admob Banner shows normally 3- Play audio 4- Exit app 5- resume app by click push notification to come to last opened activity 6- Admob banner disappears leaving its place occupied and when click on its place redirects me to google ads page ( same behaviour as ad clicked )

Expected results:

when resume activity admob banner rebuild or keep showing

Actual results:

Admob banner disappears leaving its place occupied and when click on its place redirects me to google ads page ( same behaviour as ad clicked )

``` [√] Flutter (Channel stable, 2.10.1, on Microsoft Windows [Version 10.0.19044.1586], locale en-US) • Flutter version 2.10.1 at D:\Programs\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision db747aa133 (9 weeks ago), 2022-02-09 13:57:35 -0600 • Engine revision ab46186b24 • Dart version 2.16.1 • DevTools version 2.9.2 [√] Android toolchain - develop for Android devices (Android SDK version 31.0.0-rc5) • Android SDK at C:\Users\legab\AppData\Local\Android\sdk • Platform android-31, build-tools 31.0.0-rc5 • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189) • All Android licenses accepted. [√] Chrome - develop for the web • Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe [!] Visual Studio - develop for Windows (Visual Studio Community 2022 17.0.6) • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community • Visual Studio Community 2022 version 17.0.32126.317 X The current Visual Studio installation is incomplete. Please reinstall Visual Studio. [√] Android Studio (version 2020.3) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.10+0-b96-7249189) [√] Connected device (4 available) • sdk gphone x86 (mobile) • emulator-5554 • android-x86 • Android 11 (API 30) (emulator) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19044.1586] • Chrome (web) • chrome • web-javascript • Google Chrome 100.0.4896.75 • Edge (web) • edge • web-javascript • Microsoft Edge 100.0.1185.36 [√] HTTP Host Availability • All required HTTP hosts are available ! Doctor found issues in 1 category. ```

https://user-images.githubusercontent.com/25434640/162642744-65036d9c-c128-42d2-9656-09d1096ac553.mp4

Image 1 Image 2
maheshmnj commented 2 years ago

Hi @drahmedgabr, Thanks for filing the issue. Does this happen 100% of the time. I suspect this to be a network issue where the ad preview fails to load? Can you share the logs of flutter run -v when this issue occurs?

drahmedgabr commented 2 years ago

`> Hi @drahmedgabr, Thanks for filing the issue. Does this happen 100% of the time. I suspect this to be a network issue where the ad preview fails to load? Can you share the logs offlutter run -v` when this issue occurs?

Hello,

Yes it happens 100% times ..

this https://github.com/drahmedgabr/test_ads_project test project I wrote now to test this issue

Steps to Reproduce

1- Run App .. (it will dispaly banner + play audio in background) 2- close app (audio still working) 3- reopen app from notification 4- Banner disappeared

drahmedgabr commented 2 years ago

``> Hi @drahmedgabr, Thanks for filing the issue. Does this happen 100% of the time. I suspect this to be a network issue where the ad preview fails to load? Can you share the logs of flutter run -v when this issue occurs?

Hello,

Yes it happens 100% times ..

this Simple Test Project I wrote now to test this issue

Steps to Reproduce 1- Run App .. (it will dispaly banner + play audio in background) 2- close app (audio still working) 3- reopen app from notification 4- Banner disappeared & you can click on its place it will trigger adclick action and open web page

maheshmnj commented 2 years ago

Hi @drahmedgabr, thanks for the reproducible sample project. I am able to reproduce the issue. Probably this is happening because when the app is launched from the notification in background (terminated state) It is invoked on a separate isolate (not on main isolate)

https://user-images.githubusercontent.com/31410839/163809343-6be41e23-e89e-4994-afae-e92f470d9e93.mov

Labeling this issue for further insights from the team. Reproducible sample project can be found in above comment.

flutter doctor -v (mac) ``` [✓] Flutter (Channel stable, 2.10.4, on macOS 12.3 21E230 darwin-arm, locale en-IN) • Flutter version 2.10.4 at /Users/mahesh/Documents/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision c860cba910 (13 days ago), 2022-03-25 00:23:12 -0500 • Engine revision 57d3bac3dd • Dart version 2.16.2 • DevTools version 2.9.2 [✓] Android toolchain - develop for Android devices (Android SDK version 31.0.0) • Android SDK at /Users/mahesh/Library/Android/sdk • Platform android-32, build-tools 31.0.0 • ANDROID_HOME = /Users/mahesh/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763) • All Android licenses accepted. [✓] Xcode - develop for iOS and macOS (Xcode 13.2.1) • Xcode at /Applications/Xcode.app/Contents/Developer • CocoaPods version 1.10.2 [✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome [✓] Android Studio (version 2021.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763) [✓] IntelliJ IDEA Community Edition (version 2021.2.1) • IntelliJ at /Applications/IntelliJ IDEA CE.app • Flutter plugin version 61.2.4 • Dart plugin version 212.5080.8 [✓] VS Code (version 1.65.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.39.20220405 [✓] Connected device (3 available) • iPhone 12 Pro (mobile) • 535317A4-921C-488F-B234-C2CC6D4AE5A1 • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator) • macOS (desktop) • macos • darwin-arm64 • macOS 12.3 21E230 darwin-arm • Chrome (web) • chrome • web-javascript • Google Chrome 100.0.4896.75 [✓] HTTP Host Availability • All required HTTP hosts are available • No issues found! ```
blasten commented 2 years ago

I'm unable to reproduce this issue seems in the flutter master channel. This is probably fixed already.

blasten commented 2 years ago

I confirmed that this issue is already fixed.

brazhenko commented 5 months ago

Face the same error on v4.0.0 but only on certain devices (e.g. samsung galaxy s22 ultra). The way to reproduce didn't change.

here is my code (not a minimal example). https://pastebin.com/4JUbVCAm

Video:

https://github.com/googleads/googleads-mobile-flutter/assets/36923200/03e2f9c7-681c-4160-86bd-5997bcfa62de

daurin commented 1 month ago

The same error keeps reproducing in v5.1.0 (Samsung Galaxy s23) Does not replicate in emulator.

https://github.com/googleads/googleads-mobile-flutter/assets/46636709/a644cfa3-ca51-4211-b532-0d35bfd2d879

One way I found to solve this is to listen to the AppLifecycleListener and refresh the state again so that the banner is rebuilt:

void _onStateChanged(AppLifecycleState state) async {

    if (state == AppLifecycleState.resumed && _isAdBannerLoadedNotifier.value) {
      WidgetsBinding.instance.addPostFrameCallback((_) {
        _isAdBannerLoadedNotifier.value = true; // setState(() {});
      });
      _isAdBannerLoadedNotifier.value = false; // setState(() {});
    }
  }
duytq94 commented 1 month ago

Just test and it was fixed in 3.22.0-0.3.pre Ref: https://stackoverflow.com/a/78106710/9108773