handling ads in fragments and multiple layouts

442 views
Skip to first unread message

Joseph Rand

unread,
Jul 11, 2018, 12:50:35 AM7/11/18
to Google Mobile Ads SDK Developers
Dear Sirs,
I would appreciate your help in understanding the best way to include ads in my app.  I recently upgraded my app from a single view to multiple views using fragments.  I have two fragments for the game and each fragment has portrait and landscape layouts, plus the game layout also has right and left handed modes.  I display a banner ad in an otherwise unused area of the screen on each of these layouts.  I'm using the same banner ad ID for each of six locations and the same view ID.  The banner as only appears in right and left-handed portrait mode for the game fragment.  The configuration fragment and the landscape modes, left and right-handed, of the game fragment do not show the ad.
Do I need different banner IDs for each of these layouts?  I can't really rework the app to exclude the banner ad and switch an inner view for each of these layouts so I do need to have six different instances of the banner ad - can I get them to all be the same instance so that configuration changes do not effect the ad?
Thank you, in advance, for your help.
JR

mobileadssdk-a...@google.com

unread,
Jul 11, 2018, 7:09:13 AM7/11/18
to Joseph Rand, Google Mobile Ads SDK Developers
Hi JR,

Please note that we can only assist you with your code implementation specific to loading and showing the Ads via the Mobile Ads SDK. Since you were able to display ads in some of your layout modes (e.g. portrait), then it's safe to assume that there is no issue with your Ad Unit Id.

I'm assuming you are implementing alternative resources when creating the multiple layouts. That said, I made this modifed BannerExample app which has alternative layouts for both portrait and landscape mode (with the same Ad Unit Id and View Id for the AdView) and the test ads displayed successfully for both orientation. Thus, if you are indeed using alternative layouts for each mode, then it should have worked as expected similar to the modified sample app.

For us to further investigate on our end, could you provide to us the error code captured (using Ad events) when the ads failed to load on your end?

On the other hand, when you said "configuration changes do not effect the ad", are you pertaining to ads reloading when device orientation changes? If so, then I'm afraid this is expected behavior because the SDK doesn't cache the AdView when orientation changes. In Android, activities are destroyed and recreated when orientation changes and thus, the views (e.g. AdView) inside will be reloaded again.

Regards,
Ivan Bautista
Mobile Ads SDK Team

Joseph Rand

unread,
Jul 11, 2018, 4:13:36 PM7/11/18
to Google Mobile Ads SDK Developers
Thank you for your prompt reply.  Your information was extremely helpful.
I realized my problem was due to my layouts.  I didn't leave enough room for the ads.  I ended up putting my layout into a FrameLayout then having the AdView displayed on top of my game.
Thank you, again, for your help.  Problem solved.
JR

mobileadssdk-a...@google.com

unread,
Jul 11, 2018, 11:09:19 PM7/11/18
to Joseph Rand, Google Mobile Ads SDK Developers
Hi JR,

I'm glad that you were able to resolve the issue on your end.

Feel free to create a new thread in the forum for any other technical concerns you may have with the Mobile Ads SDK and we'll be happy to assist you.
Reply all
Reply to author
Forward
0 new messages