0

I am having an issue with Admob causing a high amount of lag when the ad is loading. I have Admob setup for both android and ios, and the problem only occurs on android. Even running on older iphones, there is little to no lag, whereas high end android phones (nexus 6p an lg g4) are having lag. I use Xamarin Studio and Monogame's framework to build my apps. I've also tried threading the ad separately.

I've searched all over for an answer, and I know I found something about the android heap limit/size? Could this be a problem? Sometimes my game even lags when it's not recieving the ad, but I believe the ad's animation may be a problem. Thank you in advance for all help!

Here is my code:

protected override void OnCreate(Bundle bundle)
    {
        base.OnCreate(bundle);

        // Create our OpenGL view, and display it

        // !IMPORTANT!
        var g = new Game1();
        //SetContentView((View)g.Services.GetService(typeof(View)));


        //createAds((View)g.Services.GetService(typeof(View)));
        createAds(g.Services.GetService<View>());

        // !IMPORTANT!
        g.Run();


    }

    private void createAds(View window)
    {
        var frameLayout = new FrameLayout(this);
        var linearLayout = new LinearLayout(this);

        frameLayout.AddView(window);


        adView = new AdView(this);
        adView.AdUnitId = AD_UNIT_ID;
        adView.AdSize = AdSize.SmartBanner;
        adView.SetBackgroundColor(Android.Graphics.Color.Transparent);


        linearLayout.AddView(adView);
        frameLayout.AddView(linearLayout);
        SetContentView(frameLayout);



        var myThread = new Thread(new ThreadStart(() =>
        {
            var requestbuilder = new AdRequest.Builder();
            RunOnUiThread(() =>
            {
                adView.LoadAd(requestbuilder.Build());
            });
        }));

        myThread.Priority = (System.Threading.ThreadPriority)(Android.OS.ThreadPriority)(-20);

        myThread.Start();

    }
Attict
  • 49
  • 1
  • 4
  • No need to run `adView.LoadAd` on a separate thread. admob already does that for you. See [here](https://developers.google.com/android/reference/com/google/android/gms/ads/AdView.html#loadAd(com.google.android.gms.ads.AdRequest)) – rpattabi Jul 19 '16 at 04:26

1 Answers1

0

A possible solution can be use interstitial ads only in the pause screen or when the player finished a level (for example). The banner shouldn't create lag or problem. Maybe you can try to load the ad before the game start (in a loading screen for example) and show it after. Here there is my template with interstitial ads and banner ads included. Every line is well commented so it's veri easy to understand: https://github.com/Odle98/MonogameAndroid-BaseApp-Ads The project is ready to be compiled, all stuff is altrady added.

Hope it might be useful :)

lorenzo
  • 627
  • 8
  • 12