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

AdMob banner ads not showing after app pause/resume #2970

Closed
faustob opened this issue Oct 9, 2023 · 50 comments
Closed

AdMob banner ads not showing after app pause/resume #2970

faustob opened this issue Oct 9, 2023 · 50 comments
Assignees
Labels
P2 Issue. Plugin Issue with the Unity plugin.

Comments

@faustob
Copy link

faustob commented Oct 9, 2023

[REQUIRED] Step 1: Describe your environment

  • Unity version: 2022.3.10f1
  • Google Mobile Ads Unity plugin version: 8.5.2
  • Platform: Android
  • Platform OS version: Android 13
  • Any specific devices issue occurs on: All Android devices tested
  • Mediation ad networks used, and their versions: Only Admob

[REQUIRED] Step 2: Describe the problem

Banner ads show correctly at app start, and as long as the app stays in focus. If users switch to a different app, or the phone locks, on app resume the banner ads are no longer visible. This only happens on Android, the same app on iOS works fine. It happens in both development and release builds.

@NVentimiglia , I see your workaround here, but I am not sure how to implement it. I tried creating a Unity plugin following https://docs.unity3d.com/Manual/android-custom-activity.html, but could not get it to work.

Is the workaround still valid?
Can you provide instructions?
Is this bug being addressed?

[ FYI, I have also posted this issue as a comment to the previous (closed) thread ]

Steps to reproduce:

Happy to provide logs or other info, just not sure what would help.
Are others seeing this behavior?

Relevant Code:

@viveksaini75
Copy link

I am also facing the same issue

@VectorViral
Copy link

Same issue ,Loots of bugs in new SDK after updating SDK from 7... to 8.5.2

@Untumuxx
Copy link

same issue

@VectorViral
Copy link

Admob is turning into trash day by day....

@faustob
Copy link
Author

faustob commented Oct 18, 2023

@NVentimiglia is there an update or workaround for this issue?
It seems pretty important to me, leading to significant loss of ad revenue.

Thanks!

@faustob
Copy link
Author

faustob commented Oct 19, 2023

I figured out (I think) how to implement the workaround from #1342 (comment)

However, the behavior did not change. Banners still disappear after an app pause/resume (eg locking the screen and returning, or switching to another app and then back).

If anybody wants to try by themselves, here's what I did:

  1. Locate UnityPlayerActivity.java in your Unity install. On my Mac, this is the path:
    /Applications/Unity/Hub/Editor/2022.3.11f1/PlaybackEngines/AndroidPlayer/Source/com/unity3d/player/UnityPlayerActivity.java

  2. Replace onResume() with this code:

import android.app.KeyguardManager;
import android.app.KeyguardManager.KeyguardDismissCallback;
import android.content.Context;

//...

    @Override
    protected void onResume() {
        super.onResume();
        mUnityPlayer.resume();
        KeyguardManager keyManager = (KeyguardManager) this.getSystemService(Context.KEYGUARD_SERVICE);
        KeyguardDismissCallback keyguardDismissCallback = new KeyguardDismissCallback() {
            @Override
            public void onDismissSucceeded() {
            }

            @Override
            public void onDismissError() {
            }

            @Override
            public void onDismissCancelled() {
            }
        };
        keyManager.requestDismissKeyguard(this, keyguardDismissCallback);
    }
  1. Build for Android and test on device.

Hopefully somebody can figure out how to take it from here...

@NVentimiglia
Copy link
Member

@faustob

Thanks for your patience, I was out.

First, what are the replication steps for this issue. Here is what I tried 👍

  1. Start with the hello world sample.
  2. Load a banner ad.
  3. Hide the banner ad.
  4. Background the ap.
  5. Press the power button.
  6. Wait 2 minutes.
  7. Press power button and return to app.
  8. Show the ad.

When doing this, the banner ad showed as expected.

Second, The android custom activity is a pretty complicated fix. I could try pushing for a fix using KeyguardManager, but I am concerned with unintended consequences. Could you implement a fix in C# using OnApplicaitonPause() ?

@IoannisFMG
Copy link

We have the same issue, but we are not using the Unity AdmobSDK. Rather we use our own implementation.
I think this might have something to do with a Unity Player change, rather than an Admob SDK one.

I have some findings to share.

I tested it on a Pixel (OS 13) and I noticed that if you hit home and return to the app from the device's "task manager" the app behaves normally.
If the app moves to the background fully (gets completely minimized) then the problem starts to happen.
It also happens some times after seeing an interstitial. Didn't always happen, so I guess it might have to do with the mediation that served the ad.

@NVentimiglia
Copy link
Member

@IoannisFMG if you have specific replication steps I can take another look.

@IoannisFMG
Copy link

@NVentimiglia, I'll see if I can reproduce it in a simple test project and I'll let you know. Unfortunately, I can't share company code.

@IoannisFMG
Copy link

IoannisFMG commented Oct 26, 2023

Ok. I got the same behaviour with the example in this repo.
You will find

  • the test project,
  • the exported android studio project,
  • an apk and
  • a screen recording
    of what happens in this link: https://we.tl/t-JehKUBAK0U

The screen recording is from a Pixel 6a, Android 13.
I have also tested it on a Xiaomi Mi Note 10 Lite, Android 12, with the same results.

The reproduction plan is simple.

  1. Launch the app.
  2. Load a banner ad and wait for it to appear.
  3. Hit the home button for the app to go to the background.
  4. Open the app again from the task manager or the icon on the desktop.
  5. The ad will disappear as soon as you enter the app. (hitting the hide and show buttons doesn't resolve the situation)

The project is using
Unity 2022.3.11f1
Admob SDK 8.5.2
IL2CPP scripting backend,
Minimum API 22,
Target API 33
and is built with Android Studio Giraffe | 2022.3.1 Patch 2
on an Macbook Pro with M2 Pro, Mac OS 13.5

I should mention again that this doesn't seem to be a problem with the SDK per se. I'm leaning towards it being a Unity issue.

@lucas-brasmobi
Copy link

same issue

@faustob
Copy link
Author

faustob commented Oct 27, 2023

@IoannisFMG Thanks for your efforts! Did you submit a Unity bug?

@IoannisFMG
Copy link

IoannisFMG commented Oct 27, 2023

Not yet, because I don't know if this thing needs to be a common effort between the Admob Team and Unity.

I don't know if Unity will be able to handle this without having some insight on what is not being called, or what is called and shouldn't be etc. They probably don't have access to the Admob SDK source. The same goes with the Admob team which might not have access to the Unity source code.

My company's plan doesn't have Unity source access either, so I can't dive into that code either.

I could create a ticket if @NVentimiglia has no idea why the issue happens.

@emathis11
Copy link

Downgrading from Unity 2022.3.10 to 2022.3.6 fixes the problem for us.

@faustob
Copy link
Author

faustob commented Oct 31, 2023

Thank you @emathis11 , that worked for me as well!

I will submit a bug to Unity. @IoannisFMG, may I submit the files you provided to reproduce the bug? (Alternatively, do you want to submit the bug?)

@jeffyuio1129
Copy link

The same problem occurs. Is there a solution?

@faustob
Copy link
Author

faustob commented Oct 31, 2023

The same problem occurs. Is there a solution?

What do you mean? Did you try to downgrade to 2022.3.6, as suggested above? Did that not work?

@viveksaini75
Copy link

Bro, I have been using 2021.3.21f1 for the last 7 months, and when upgraded to 8.5.2 I faced the same issue.

@viveksaini75
Copy link

I think it's not an editor bug

@IoannisFMG
Copy link

Yes, @faustob, I will submit one now. I'll share the link once it's public.

@jeffyuio1129
Copy link

jeffyuio1129 commented Oct 31, 2023

The same problem occurs. Is there a solution?

What do you mean? Did you try to downgrade to 2022.3.6, as suggested above? Did that not work?

downgrade is not possible due to other issues.

is there no solution in 2022.3.12f1?

@NVentimiglia
Copy link
Member

@IoannisFMG

The attached video did not download / work.

I am still unable to replicate the issue.

If you have a sample video and sample code, submit it to The google support group.

@IoannisFMG
Copy link

@dantech0xff
Copy link

I think this is an issue of Unity Renderer

This is the Layout inspector before pause Unity Game Activity. Can see the Surface is behide the Banner.
Screenshot 2023-11-02 at 01 16 33

This is the layout inspector after we resume. Can see, The Unity Surface covered Banner View
Screenshot 2023-11-02 at 01 13 57

@faustob
Copy link
Author

faustob commented Nov 1, 2023

@IoannisFMG

The attached video did not download / work.

I am still unable to replicate the issue.

If you have a sample video and sample code, submit it to The google support group.

@NVentimiglia FYI - First time I tried to download I missed that I had to "Accept terms and conditions" on the page to access the file.

@NVentimiglia
Copy link
Member

@faustob

Ty for your feedback, I will talk with that team to see if we can streamline file uploading.

@NVentimiglia
Copy link
Member

Internal bug id for reference b/308855324

The fact that Unity pushes the banner behind the game is a problem worth looking into.

@NVentimiglia NVentimiglia added P2 Issue. Plugin Issue with the Unity plugin. labels Nov 1, 2023
@faustob
Copy link
Author

faustob commented Nov 1, 2023

@faustob

Ty for your feedback, I will talk with that team to see if we can streamline file uploading.

I meant to say that I had that problem when trying to download the files created by @IoannisFMG from this link. He included a video as well as sample code to replicate the issue. Thought you may have had the same issue. Sorry for the confusion.

@dantech0xff
Copy link

Hey bros, In the mean time what is a work around solution here. Down grade Unity to a particular version?

@itamishi
Copy link

itamishi commented Nov 5, 2023

The only "workaround" I came up with is to create a new banner every time the app unpauses.

I'm NOT SURE if it's a violation of AdMob policy, as it probably counts as a separate banner show

    private void OnApplicationPause(bool pause) {
#if !UNITY_EDITOR && UNITY_ANDROID
        if (!pause) {
            Banner.Instance.CreateBannerView();
        }
#endif
    }

Banner code: (its a Singleton)

    public void CreateBannerView() {
        Debug.Log("Creating banner view");

        if (_bannerView != null) {
            DestroyBannerView();
        }

        _bannerView = new BannerView(_adUnitId, AdSize.Banner, AdPosition.Bottom);

        var adRequest = new AdRequest();
        _bannerView.LoadAd(adRequest);
    }

I think of implementing some sort of timer (of 1 minute for example) so the user can't spam minimize/maximize app, to make it a bit safer

EDIT: Not worth the headache, downgrading to Unity 2022.3.6 (2022.3.0 in my case) is the best solution imo, as it fixes the issue completely

@faustob
Copy link
Author

faustob commented Nov 6, 2023

For me all it took was downgrading to Unity 2022.3.6, as suggested above (newer versions have the issue.) That version has an issue compiling for iOS, so I now switch between the two version to build for Android and iOS :(

@faustob
Copy link
Author

faustob commented Nov 9, 2023

@IoannisFMG any update on bug submission? Thanks!

@IoannisFMG
Copy link

Unfortunately no updates, @faustob. The ticket I submitted is still open. They haven't even looked at it, yet.

@ld07
Copy link

ld07 commented Nov 12, 2023

Same problem here... But Unity version 2021.3.32. My workaround was downgrading to Unity 2021.3.29. It seems that the problem arose as a side effect of this fix that was made in both Unity 2021.3.30 and 2022.3.6:

image

"Android: Fixed an issue where pause was not processed when onPause() is called right after onResume() is called. (UUM-23247)"

@NVentimiglia NVentimiglia self-assigned this Nov 14, 2023
@IoannisFMG
Copy link

By the way, the Incident number I reported is IN-59336. In case needed somewhere.

@NVentimiglia
Copy link
Member

Closing this issue. Please reopen if Unity gets back to you and has next steps for us.

@hasnain-shukat
Copy link

Happening in Unity 2022.3.12 too.

@shefich
Copy link

shefich commented Nov 23, 2023

Happening in Unity 2022.3.13 and 2022.3.14.

@IoannisFMG
Copy link

Yesterday, they put the issue I submitted in Review. I'll keep you posted.

@IoannisFMG
Copy link

The bug has been confirmed and it has been forwarded to Unity's dev team.
For reference, the internal ID is UUM-57151.

I'll post any updated I receive here.

@povilasxd3
Copy link

Hi everyone!
The issue has now been processed and you can follow its progress in the Issue Tracker here: https://issuetracker.unity3d.com/product/unity/issues/guid/UUM-57151
Thank you all for your patience

@oraylan
Copy link

oraylan commented Nov 28, 2023

I'm having the same problem here, apparently different people are having it. But I already saw that they opened a ticket, let's wait. Or does anyone already have a solution?

@ProBoss1
Copy link

ProBoss1 commented Dec 3, 2023

I'm having the same problem here, apparently different people are having it. But I already saw that they opened a ticket, let's wait. Or does anyone already have a solution?

I downgrade Unity form 2022.3.14f1 LTS to 2022.3.6f1 LTS and issue solved.

@Unarmed1000
Copy link

Unarmed1000 commented Dec 5, 2023

Given that the "New Consent Management Platform requirements" take effect January 16, 2024. It would seem critical to get a fix out asap so people have a chance of doing a release before then.

With such a important deadline imposed by Google it seems kind of strange to just 'close' this very real issue and take a lets wait and see attitude to the problem. Ignoring the fact that lots of apps have been forced to do a update around this time to make it in time for the deadline.

This really would be the time to take the issue seriously and contact Unity directly to get the critical issue fixed before their next LTS releases.

@Unarmed1000
Copy link

@NVentimiglia given the upcoming deadline imposed by google that requires apps to be updated before Jan16, would it not make sense to take charge of this and work with unity to solve this asap so all the Unity apps can be updated in time?

@IoannisFMG
Copy link

A fix for your bug report IN-59336: [Android] AdmobSDK banner ad disappears when the device goes to the home screen and returns to the application has been submitted with the following status: Fixed and currently awaits internal confirmation.

Fix Version/s: Pending

A fix is probably coming soon to an Editor version near you.

@faustob
Copy link
Author

faustob commented Dec 15, 2023

FYI, from https://issuetracker.unity3d.com/issues/android-admobsdk-banner-ad-disappears-when-the-device-goes-to-the-home-screen-and-returns-to-the-application

Under Consideration for 2021.3.X, 2024.1.X

Fixed in 2022.3.16f1, 2023.3.0a19

In Progress in 2023.2.X

Waiting for 2022.3.16f1 to be released...

@faustob
Copy link
Author

faustob commented Dec 21, 2023

2022.3.16f1 was released and based on my initial testing the bug is finally fixed.

As far as other editor versions, current state is:

Under Consideration for 2021.3.X, 2024.1.X
Fixed in 2022.3.16f1, 2023.3.0a19
In Progress in 2023.2.X

@mdolzhansky
Copy link

I upgrated unity to 2021.3.36f1 and now it fixed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P2 Issue. Plugin Issue with the Unity plugin.
Projects
None yet
Development

No branches or pull requests