Showing Admob banner inide an Alert Dialog within a service (no Avtivity)

1,308 views
Skip to first unread message

Hijane Moulay

unread,
Aug 8, 2016, 10:20:55 AM8/8/16
to Google Mobile Ads SDK Developers
I am trying to show an Admob banner, inside and alert dialog that is displayed by foreground service (I am using test banner addTestDevice...)
So far so good, the banner is shown correctly inside the dialog.
But there is a strange behavior.
Sometimes, When I click on the banner, the click is ignored and the Log is :

W/Ads: The webview does not exit. Ignoring action.
I/Ads: Ad closing.
I have to lick at least two time to open the add!!! Weird behavior.

I also have another question about monetization:

As I destroy the banner after the user has clicked on using event Ad listener onAdLeftApplication(), does it affect the monetization of that click? I mean, am I going to earn something from that click, or it is a click in vain?
Any idea?
Many thanks in advance

Here How I use the banner

/**
 * Load Admob banner is as backup for Native Ads
 *
 * @param adPlaceHolder the view to be populated
 */
private void populateRegularBannerAd(final FrameLayout adPlaceHolder) {
    Log.i(TAG, "Loading Banner Ad");

    bannerAdView = new AdView(MyApp.getAppContext());
    bannerAdView.setAdSize(AdSize.LARGE_BANNER);
    bannerAdView.setAdUnitId(MyApp.getAppContext().getResources().getString(R.string.admob_banner_id));
    bannerAdView.setAdListener(new AdListener() {
        @Override
        public void onAdLoaded() {
            super.onAdLoaded();
BANNER_ADS_NB_SUCCESSIVE_FAIL = 0;
            Log.i(TAG, "Banner Ad loaded OK");
        }

        @Override
        public void onAdFailedToLoad(int errorCode) {
            Log.w(TAG, "Failed to load banner ad: " + errorCode);
            if (Utils.isOnline())
                BANNER_ADS_NB_SUCCESSIVE_FAIL++;
            Utils.freeMemory();
            populateBackupBannerAd(adPlaceHolder);

        }


        @Override
        public void onAdLeftApplication() {
            Intent broadcast = new Intent();
            broadcast.setAction("CLOSE_DIALOG");
            MyApp.getAppContext().sendBroadcast(broadcast);
        }
    });

    AdRequest adRequest = new AdRequest.Builder()
            .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            .addTestDevice(TEST_DEVICE)
            .build();
    bannerAdView.loadAd(adRequest);
    if (adPlaceHolder != null) {
        try {
            adPlaceHolder.removeAllViews();
            adPlaceHolder.addView(bannerAdView);
            adPlaceHolder.addOnAttachStateChangeListener(new View.OnAttachStateChangeListener() {
                @Override
                public void onViewAttachedToWindow(View view) {

                }

                @Override
                public void onViewDetachedFromWindow(View view) {
                    // if not destroyed, the banner keeps trying to refresh even when detached
                    if (bannerAdView != null) {
                        try {
                            Log.i(TAG, "destroying Banner............");
                            bannerAdView.pause();
                            bannerAdView.setAdListener(null);
                            adPlaceHolder.removeAllViews();
                            bannerAdView.destroy();
                            bannerAdView = null;
                        } catch (Exception e) {
                            // do nothing
                        }
                    }
                }
            });
        } catch (Exception e) {
            // do nothing
            e.printStackTrace();
        }
    }
}


Vu Chau (Mobile Ads SDK Team)

unread,
Aug 8, 2016, 2:38:40 PM8/8/16
to Google Mobile Ads SDK Developers
Hi Hijane,

Would you be able to send us a mini project (with your AlertDialog-handling logic) where we can see this behavior in action?
I was able to trigger the clickthrough with only one tap.  Make sure that your banner adview isn't out of focus (which might require the additional tap).

Thanks,

Vu Chau
Mobile Ads SDK Team
Reply all
Reply to author
Forward
0 new messages