Game closes when ad is run

Hi,

I have just integrated ads into my game and it works fine within Unity. However when I go to run the build on my android, when it should show an ad the game just restarts.

    void Start ()
    {
        gameManager = FindObjectOfType<GameManager> ();
    }

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

        if (gameManager.adCounter > 3) {
            gameManager.adCounter = 0;
            shown = false;
        }

        if (!Advertisement.isShowing) {
            if (!shown) {
                PlayAd ();
            }
        }
    }

    void OnMouseUp ()
    {
    }

    void PlayAd ()
    {
        if (Advertisement.IsReady ()) {
            var options = new ShowOptions { resultCallback = HandleShowResult };
            Advertisement.Show (null, options);
            shown = true;
        }
    }

    private void HandleShowResult (ShowResult result)
    {
        switch (result) {

        case ShowResult.Finished:
            Debug.Log ("Finished ad");
            break;

        case ShowResult.Failed:
            break;

        case ShowResult.Skipped:
            break;

        default:
            break;
        }
    }

Any ideas what I have done wrong?

Kind Regards

Sounds similar to Unity ads crashes on a LG Google Nexus 4, Unity 5.3.5f1 Personal - Unity Services - Unity Discussions. Can you follow the instructions on that thread and post device log?

Thanks,
Rasmus

Hi,

I have managed to get the device log. The tablet I am using is the nexus 7. I hope I have provided the right information in the log. (This is my first time using ADB).

A fellow student of mine tested my application on their tablet and the ads run absolutely fine.

If you need any more information please let me know!

Kind Regards
Andy

2677399–189062–tabletAdProblem_Nexus7.txt (32.8 KB)

Does it stop

  1. at the moment of showing the ads
    or
  2. when resuming the game after an Ad?

In the second case it looks a lot like this thread in which they discovered that it was related to an Android option (Settings > Developer Options > Don’t Keep Activities > OFF)

It occurs at the moment of showing the ad.

(Settings > Developer Options > Don’t Keep Activities > OFF) - I changed these settings to be off. And now the ads functionality displays but says video playback error.

Any idea what could be causing the playback error?

Is there anyway to get these settings to change on the device when it is installed? Obviously the user isn’t going to know to change this setting.

Kind Regards

I haven’t integrated Unity Ads yet so I can’t tell for your playback error (are you in test mode? Is there any log for this playback error? Is your project correctly configured on unity services platform?).

You shouldn’t worry about this on your user’s devices. As stated by the option it’s a “Developer” option.
Here’s what I found regarding why is this option exists