Calling interstitialAd.show() in other, non-activity class

563 views
Skip to first unread message

vipme...@gmail.com

unread,
Jul 7, 2017, 10:15:01 AM7/7/17
to Google Mobile Ads SDK Developers
Hello, i'm new, and guess i really need help now. I don't know how i can call method from activity class in other non-activity class (my main class GameScreen). Coz i need to show interstitial ad in the end of level.

1. I have an Activity class in this class: public class AndroidLauncher extends AndroidApplication implements IActivityRequestHandler

in this class i loading interstitial ad.


interstitial = new InterstitialAd(this);
interstitial.setAdUnitId("ca-app-pub-9506272630021404/5753886777");
AdRequest adRequesti = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("0123456789ABCDEF")
.build();
interstitial.loadAd(adRequesti);

And have method displayInterstitial()

public void displayInterstitial() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}

2.I have GameScreen class in this class: public class GameScreen implements Screen
in this class i have method isWin(), where i want to show interstitial ad (by calling displayInterstitial())


Please help, how can i call displayInterstitial() (activity class method) from GameScreen class (non-activity method). Thanks a lot.

Deepika Uragayala- MobileAds SDK team

unread,
Jul 7, 2017, 3:05:06 PM7/7/17
to Google Mobile Ads SDK Developers
Hi there,

The InterstrialAd  object expects the root Activity to be loaded and available to present another Intent, being our AdView. We suggest that you create your Adview instance from the Activity to give a direct context from where it's being presented and this gives you a direct control to work with your Activity lifecycle, like in case, the Activity onDestroy() is called, you can destroy the Adview as well. So in your case we recommend to give the direct Activity context to the Adview and present from there.

Regards,
Deepika Uragayala
Mobile Ads SDK Team

vipme...@gmail.com

unread,
Jul 9, 2017, 8:52:48 AM7/9/17
to Google Mobile Ads SDK Developers
Just wanna to clear, we talking about interstitial ad, right? Didn't see AdView using with interstitial ad. Can i see some example of calling interstitial ad from non-activity class?
Thanks a lot

пятница, 7 июля 2017 г., 23:05:06 UTC+4 пользователь Deepika Uragayala- MobileAds SDK team написал:

Deepika Uragayala- MobileAds SDK team

unread,
Jul 10, 2017, 1:44:08 PM7/10/17
to Google Mobile Ads SDK Developers
Hi,

Just wanna to clear, we talking about interstitial ad, right?
Yes, I meant InterstitialAd.


Can i see some example of calling interstitial ad from non-activity class?
You can only call from with an Activity context so create the InterstitialAd instance with a reference to that Context.

Let me know if you have any other questions. I will be happy to assist you.

Regards,
Deepika Uragayala
Mobile Ads SDK Team


vipme...@gmail.com

unread,
Jul 11, 2017, 1:55:18 AM7/11/17
to Google Mobile Ads SDK Developers
Thank you, the problem is solved by using an interface class. Thank you for your time.


понедельник, 10 июля 2017 г., 21:44:08 UTC+4 пользователь Deepika Uragayala- MobileAds SDK team написал:
Reply all
Reply to author
Forward
0 new messages