Unity freeze after close interstitial AD

591 views
Skip to first unread message

Bill Chung

unread,
Jan 15, 2017, 9:12:38 AM1/15/17
to Google Mobile Ads SDK Developers
Hi,

I'm using Unity 5.4.2f2 for Android with Admob, sometime when I watching an interstitial AD, finish and close it, my game was freeze, I can hear music is still playing but screen can't rotate, nothing can do when I touch any button, also on Device Monitor I can't see any error message, I have no idea why this happen. How can I fix it?

Thanks~

Ivan Bautista (Mobile Ads SDK Team)

unread,
Jan 16, 2017, 1:14:37 AM1/16/17
to Google Mobile Ads SDK Developers
Hi Bill,

Can you try running your Ad Unit ID/s in question to one of our sample apps and see if the issue persist? Also, can you provide us a sample project/code snippet that contains the implementation where you think the problem is reproducible.

Best Regards,
Ivan Bautista
Mobile Ads SDK Team

Bill Chung

unread,
Jan 16, 2017, 10:35:49 PM1/16/17
to Google Mobile Ads SDK Developers
Hi Ivan, thank you for reply and sorry for late

I had try these sample projects before and all works, but I should do more test and see if that issue happen.
Here is my code:

using UnityEngine;
using System.Collections;
using GoogleMobileAds.Api;
using System;

public class TestAD : MonoBehaviour
{
    InterstitialAd interstitial;

    // Use this for initialization
    void Start()
    {
        RequestInterstitial();
    }

    // Update is called once per frame
    void Update()
    {
 
    }

    public void Show()
    {
        if (interstitial.IsLoaded())
        {
            Debug.Log("Show AD");
        }
        else
        {
            Debug.Log("AD not ready");

            //Do something here
        }
    }

    public void RequestInterstitial()
    {
        if (interstitial != null && interstitial.IsLoaded())
        {
            return;
        }

#if UNITY_ANDROID
        string UnitID = "my Android UnitID";
#elif UNITY_IOS
        string UnitID = "my iOS UnitID";
#endif

        if (interstitial != null)
        {
            Debug.Log("interstitial not null");
            DestroyInterstitial();
        }
        else
        {
            Debug.Log("interstitial is null");
        }

        interstitial = new InterstitialAd(UnitID);

        interstitial.OnAdLoaded += HandleInterstitialLoaded;
        interstitial.OnAdFailedToLoad += HandleInterstitialFailedToLoad;
        interstitial.OnAdOpening += HandleInterstitialOpened;
        interstitial.OnAdClosed += HandleInterstitialClosed;
        interstitial.OnAdLeavingApplication += HandleInterstitialLeftApplication;
        
        AdRequest request = new AdRequest.Builder().Build();
        
        interstitial.LoadAd(request);
    }

    void DestroyInterstitial()
    {
        interstitial.Destroy();
        interstitial = null;
    }
    
    public void HandleInterstitialLoaded(object sender, EventArgs args)
    {
        Debug.Log("HandleInterstitialLoaded");
    }

    public void HandleInterstitialFailedToLoad(object sender, AdFailedToLoadEventArgs args)
    {
        Debug.Log("HandleInterstitialFailedToLoad : " + args.Message);
    }

    public void HandleInterstitialOpened(object sender, EventArgs args)
    {
        Debug.Log("HandleInterstitialOpened");
    }

    public void HandleInterstitialClosed(object sender, EventArgs args)
    {
        Debug.Log("HandleInterstitialClosed");

        DestroyInterstitial();
        
        //Do something here
        
        RequestInterstitial();
    }
    
    public void HandleInterstitialLeftApplication(object sender, EventArgs args)
    {
        Debug.Log("HandleInterstitialLeftApplication");
    }
}

And here is a snippet of my AndroidManifest.xml.
I was looking for some similar questions that mention about modify the manifest file, I'm not good about this...maybe the issue is here?
  <activity 
      android:name="com.unity3d.player.UnityPlayerProxyActivity" 
      android:launchMode="singleTask" 
      android:label="@string/app_name" 
android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
      
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <category android:name="android.intent.category.LAUNCHER" />
      </intent-filter>
    </activity>
    <activity 
      android:name="com.unity3d.player.UnityPlayerActivity" 
      android:launchMode="singleTask" 
      android:label="@string/app_name" 
      android:configChanges="fontScale|keyboard|keyboardHidden|locale|mnc|mcc|navigation|orientation|screenLayout|screenSize|smallestScreenSize|uiMode|touchscreen">
    </activity>
    
    <activity
      android:name="com.unity3d.player.UnityPlayerNativeActivity"
      android:label="@string/app_name">
 
      <intent-filter>
        <action android:name="android.intent.action.MAIN" />
        <!--<category android:name="android.intent.category.LAUNCHER" /> -->
      </intent-filter>
      
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
      <meta-data android:name="unityplayer.ForwardNativeEventsToDalvik" android:value="true" />
    </activity>



Ivan Bautista (Mobile Ads SDK Team)於 2017年1月16日星期一 UTC+8下午2時14分37秒寫道:

Ivan Bautista (Mobile Ads SDK Team)

unread,
Jan 17, 2017, 1:48:38 AM1/17/17
to Google Mobile Ads SDK Developers
Hi Bill,

Do you still experience the game freeze on your app after closing the interstitial ad? I tried running your code on my end and just added the interstitial.Show() in the Show() method as well as a trigger to call the Show() method and was able to run the app smoothly without any significant lag.

Best Regards,
Ivan Bautista
Mobile Ads SDK Team

Bill Chung

unread,
Jan 17, 2017, 10:21:58 AM1/17/17
to Google Mobile Ads SDK Developers
Hi Ivan,

I tried several times and not happen but I'm not sure when it will happen. 
By the way if that issue happen, interstitial AD is close and back to the game, although my game is freeze but I can still receive the callback say AD is loaded (HandleInterstitialLoaded function called)

Ivan Bautista (Mobile Ads SDK Team)於 2017年1月17日星期二 UTC+8下午2時48分38秒寫道:
Reply all
Reply to author
Forward
0 new messages