- Home /
Android thread causes crash?
Hi, I am using a thread to initialize admob to prevent lag caused by it initializing in the player script. But whenever I launch my app, it crashes.
void Start () {
Thread adThread = new Thread(new ThreadStart(bannerAdSetup));
adThread.Start();
}
public void bannerAdSetup()
{
Banner View bannerView = new BannerView(
"MyAdkey", AdSize.Banner, AdPosition.Bottom);
AdRequest request = new AdRequest.Builder().Build();
bannerView.LoadAd(request);
}
Any ideas why this crashes?
Any help is greatly appreciated, thanks.
Comment
Answer by Yury-Habets · Jan 04, 2016 at 08:32 AM
I would assume this code makes JNI calls from the custom thread (AndroidJava* API).
Unfortunately this does not work with Unity at the moment.
As a workaround, do the Java call from the main thread, then, in Java, create a thread that is used for initialization and return immediately. This way you won't stall the main thread.