Custom Renderer Control does not appear until I navigate away then back to page on device.

ciano1000ciano1000 Member ✭✭
edited October 2018 in Xamarin.Forms

Hey guy's, was following the admob tutorial and got everything working perfectly in the emulator, ads showed up perfectly. However, on my physical device, the ads don't show up at all unless I navigate away from the page then return. It's very strange and annoying, anyways my custom renderer code is below and I hope someone knows whats going on!

public class AdViewRenderer : ViewRenderer<AdControlView, AdView>
{              
     //Note you may want to adjust this, see further down.
     AdSize adSize = AdSize.SmartBanner;
     AdView adView;
     Location location;             

     AdView CreateNativeAdControl()
     {          
            var adUnitId = ((AdControlView)Element).AdUnitID;
            if (adView != null)
                return adView;

            adView = new AdView(Android.App.Application.Context);
            adView.AdSize = adSize;
            adView.AdUnitId = adUnitId;
            var adParams = new LinearLayout.LayoutParams(LayoutParams.WrapContent, LayoutParams.WrapContent);

            adView.LayoutParameters = adParams;
            var request = new AdRequest.Builder();           

        adView.LoadAd(request.Build());
            return adView;
     }

     protected override void OnElementChanged(ElementChangedEventArgs<AdControlView> e)
     {

        base.OnElementChanged(e);
            if(Control == null)
        {
               CreateNativeAdControl();
               SetNativeControl(adView);
            }            

       }

     public AdViewRenderer(Context context):base(context)
     {

     }
}

Answers

  • BillyLiuBillyLiu Member, Xamarin Team Xamurai

    @ciano1000

    What's your target Android version? And have you tried to wait for a few longer?
    I have tested your code both on Google Pixel(Android 8.1) and emulator. They all work fine.
    Could you share your project?

  • ciano1000ciano1000 Member ✭✭

    @BillyLiu I have overall tried testing with three devices (a One Plus 2 ,a Samsung A5 and a Samsung S7), it worked perfectly on the One Plus but not on either of the samsung's I believe this may be some issue with xamarin on Samsung device's. Btw I'm targeting android 8.1(due to the new google play rule's) with a min Android version of 6.0(which my one plus is running).

  • ActivActiv Member ✭✭

    @ciano1000 did you fix it? i have the same error and i don't know how to do it.

  • kalkoskikalkoski FIMember ✭✭

    @ciano1000 said:
    @BillyLiu I have overall tried testing with three devices (a One Plus 2 ,a Samsung A5 and a Samsung S7), it worked perfectly on the One Plus but not on either of the samsung's I believe this may be some issue with xamarin on Samsung device's. Btw I'm targeting android 8.1(due to the new google play rule's) with a min Android version of 6.0(which my one plus is running).

    I'm having similar problem. Can you check the WebView-version on each device ?
    I'm using Nokia 8 and the Chome (Web View) version is 70.0.3538.80.
    I tried to install Chrome beta and use newer web view but it didn't help.

  • ActivActiv Member ✭✭
    > @kalkoski said:
    > @ciano1000 said:
    > @BillyLiu I have overall tried testing with three devices (a One Plus 2 ,a Samsung A5 and a Samsung S7), it worked perfectly on the One Plus but not on either of the samsung's I believe this may be some issue with xamarin on Samsung device's. Btw I'm targeting android 8.1(due to the new google play rule's) with a min Android version of 6.0(which my one plus is running).
    >
    >
    >
    >
    >
    > I'm having similar problem. Can you check the WebView-version on each device ?
    > I'm using Nokia 8 and the Chome (Web View) version is 70.0.3538.80.
    > I tried to install Chrome beta and use newer web view but it didn't help.

    But after refresh screen, like a after a interstitial or back screen, the banner appears? I have this problem.
  • ActivActiv Member ✭✭
    Do you work in Mac or Windows?
Sign In or Register to comment.