SDL2+Android+Admob Banner Problem

Hi to All.
It is a strange problem. Although admob banner appears in my SDL2 game, if i press home button on device to exit game and then return back, admob banner dissappears. Home button prevents any banner from appearing.
I saw that SDL2 destroys surfaces on home button press. After returning to game, code to create banner fails.
Code i use onCreate of my activity is:

mAdView = new AdView(mSingleton);
mAdView.setAdListener(new AdListener(){
@Override
public void onAdLoaded() {
Log.v(“SDL”, “Banner Loaded”);
ShowAd_Banner();
// Save app state before going to the ad overlay.
}
});
mAdView.setAdSize(AdSize.SMART_BANNER);
mAdView.setAdUnitId(“ca-app-pub-3940256099942544/6300978111”);

    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);

    params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    params.addRule(RelativeLayout.CENTER_HORIZONTAL);

    mLayout.addView(mAdView, params);
    HideAd_Banner();

    adRequest_Banner = new AdRequest.Builder()
            .addTestDevice("BF5D02AD5253A91B55F6019BCEEE0C96")
            .build();
    mAdView.loadAd(adRequest_Banner);

And on build.gradle

dependencies {
compile fileTree(include: [’*.jar’], dir: ‘libs’)
compile ‘com.google.firebase:firebase-ads:10.0.1’
}

apply plugin: ‘com.google.gms.google-services’

Update: I found what caused this issue. I was using SDL_SetRenderTarget in my c++ SDL2 code to render directly to texture and this prevented admob banner from showing up after home button press. Now on my activity onPause, i switch rendering from texture to main renderer and banners work fine. And onResume of activity i switch again to texture rendering.

I found what caused this issue. I was using SDL_SetRenderTarget in my c++ SDL2 code to render directly to texture and this prevented admob banner from showing up after home button press. Now on my activity onPause, i switch rendering from texture to main renderer and banners work fine. And onResume of activity i switch again to texture rendering.

1 Like

Hi JohnD.
I have a problem about setting google admob in to SDL android project.
I am using your code.
Can you share for me full code for this one.
Your code is missing two function: HideAd_Banner() and ShowAd_Banner().
and can you share for me the way to fixed admob not show. ? ( cause: SDL_SetRenderTarget)
Thank you so much.