'Unity. Closing the android phone screen during the ad display process causes a black screen to appear

I'm trying to implement unity ads for the first time in an android game. Everything seems to be working properly except for one thing. When the ShowAd method is called it takes 2 seconds for the advertisement to be actually displayed, during which time if you turn off and open the phone screen, the game stops, superimposing a black screen on the screen. I think what really happens is that the ad starts in the background until the application loses its focus, and when I reopen the phone the ad closes automatically leaving only the black screen. I thought that to avoid this, I should reload the application based on a check in onapplicationfocus function, such as: if the user pressed the lock button on the phone, if the screen is closed, or simply a check if the application is lost focus due to the ad or another event. Another solution would be to configure the application to run in the background somehow, but I did not manage to apply any of the above. Does anyone know how to apply one of the above? Thanks in advance!



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source