- Whoever downvotes - please explain, I am trying to learn, not an expert programmer and looking for assistance whilst trying to figure what is wrong - downvoting me is not helpful when someone is trying to learn.
In my android project, I have several .java files, one of them being a Global.java file.
What I would like to do, is create a method that I can call simply by using;
Global.showAdmob();
from any of the other java files.
The problem I have is, when I try to create the method inside the Global.java file, it mentions 'cannot use this in a static context'
Here is what I am trying to call from the other files;
private static InterstitialAd interstitial;
public static void displayInterstitial1() {
if (interstitial.isLoaded()) {
interstitial.show();
}
}
public static void showAdmob() {
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(MY_AD_UNIT_ID);
AdRequest adRequest = new AdRequest.Builder().build();
interstitial.loadAd(adRequest);
interstitial.setAdListener(new AdListener(){
public void onAdLoaded(){
displayInterstitial1();
}
public void onAdClosed(){
}
public void onAdFailedToLoad(int errorCode){
}
});
}