-
Notifications
You must be signed in to change notification settings - Fork 271
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
Reference to old GoogleMobileAdsViewFactory after flutter activity is recreated [Android] #265
Comments
Any updates on this? Does the plugin support a cached flutter engine? I can not get it to load ads when starting the flutter engine when the application starts. Below are some errors from the log:
Here is an example project that was used to generate the above logs: https://github.com/rckrdstrgrd/googleads-mobile-flutter-issue-265 |
Loading ads from a cached engine currently does not work. This happens because After fixing this I'm able to load and show an ad the first time we open the FlutterActivity. However I get this new error when showing the Flutter activity again after closing it:
@blasten @bparrishMines do you know if PlatformViews support this use case? Or if there's some API we need to call between showing the Flutter Activity again to reset the PlatformsViewsController state? |
So it looks like when an engine is detached from a Despite that, the old I think you were looking to use the old Also from: https://developer.android.com/guide/components/activities/activity-lifecycle#ondestroy
|
It should be possible to at least load ads from a cached engine the first time. Based on what @bparrishMines said, reusing the cached engine to redisplay ads is trickier. It may be possible to use MutableContextWrapper to update the context, but based on this stackoverflow post there could be unintentional bugs from switching the context. Imo it's worth at least exploring. |
There's an issue in the implementation that affects all platform views, so this is a Flutter bug. |
This should be resolved by flutter/engine#28894 |
Plugin Version
0.13.0
Steps to Reproduce
When testing the plugin in a flutter add-to-app Android project, using a cached FlutterEngine. The ads stops working after the flutter activity is closed and then reopened, i.e the flutter activity is destroyed and recreated. The ads are blank or display an error view. If there isn't something wrong in my project setup I think this is caused by an old/wrong reference to
GoogleMobileAdsViewFactory
after the activity is recreated.When the activity is recreated
GoogleMobileAdsPlugin.onAttachedToActivity
is called and theninitializePlugin
.initializePlugin
will create a new view factory and attempt to register it, but the registration of the new view factory will fail since thePlatformViewRegistry
do not allow updates. This results in an outdated/mismatched reference for theAdInstanceManager
betweenGoogleMobileAdsViewFactory
andGoogleMobileAdsPlugin
.Does the plugin support the flutter activity to be recreated?
Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/rickard/Dev/Android/sdk
• Platform android-30, build-tools 30.0.3
• ANDROID_HOME = /Users/rickard/Dev/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 11.0.8+10-b944.6916264)
The text was updated successfully, but these errors were encountered: