# Interstitial ad

**URL:** <https://discourse.processing.org/t/interstitial-ad/14338>\
**Category:** Processing for Android\
**Created:** [October 1, 2019, 7:08am UTC](https://discourse.processing.org/t/interstitial-ad/14338 "2019-10-01T07:08:04Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Yash](https://avatars.discourse-cdn.com/v4/letter/y/f17d59/32.png) [@Yash](https://discourse.processing.org/u/Yash)\
**Post date:** [October 1, 2019, 7:08am UTC](https://discourse.processing.org/t/interstitial-ad/14338/1 "2019-10-01T07:08:04Z")

</div>

hello everyone ive completed creating my game…but iam facing so much trouble from 2 weeks implementing either interstitial or video ads.The code executes without any error ads doesnt show.i want to publish my app…any help will be so much appreciated…pls help.

import android.os.Looper;//for setup() if needed  
import android.os.Bundle;  
import android.view.Window;  
import android.widget.RelativeLayout;  
import android.app.Activity;  
//import com.google.ads.\*;//  
import com.google.android.gms.ads.AdRequest;  
import com.google.android.gms.ads.AdView;  
import com.google.android.gms.ads.AdSize;  
import com.google.android.gms.ads.MobileAds;

private InterstitialAd mInterstitialAd;

public void setup() {  
size(800, 1000);  
}

public void draw() {  
background(100);  
rect(100, 100, 100, 100);  
}  
@ Override  
public void onCreate(Bundle savedInstanceState) {  
print(“on create”);  
super.onCreate(savedInstanceState);  
Window window = getActivity().getWindow();  
RelativeLayout adsLayout = new RelativeLayout(this.getActivity());  
RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(  
RelativeLayout.LayoutParams.WRAP\_CONTENT, RelativeLayout.LayoutParams.MATCH\_PARENT);  
MobileAds.initialize(this.getActivity(), “ca-app-pub-3940256099942544~3347511713”);  
mInterstitialAd = new InterstitialAd(this.getActivity());  
mInterstitialAd.setAdUnitId(“ca-app-pub-3940256099942544/1033173712”);  
mInterstitialAd.loadAd(new AdRequest.Builder().build());  
if (mInterstitialAd.isLoaded()) {  
mInterstitialAd.show();  
} else  
{  
print(“not loaded”);  
}

window.addContentView(adsLayout, lp2);  
}

---

<div class="post-metadata">

**Author:** ![kll](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kll/32/964_2.png) [@kll](https://discourse.processing.org/u/kll)\
**Post date:** [October 1, 2019, 8:09am UTC](https://discourse.processing.org/t/interstitial-ad/14338/2 "2019-10-01T08:09:49Z")

</div>

please format your code  
using the `</> Preformatted text` button from the editor header menu

and repair above code posting.  
( it shows many errors regarding “” as we use `""` in JAVA )

* * *

i hope someone can help you ( i not even know what you are talking about )  
still i think that you should get a error about a missing import

```auto
import com.google.android.gms.ads.InterstitialAd;

```

??

---

<div class="post-metadata">

**Author:** ![Yash](https://avatars.discourse-cdn.com/v4/letter/y/f17d59/32.png) [@Yash](https://discourse.processing.org/u/Yash)\
**Post date:** [October 1, 2019, 9:21am UTC](https://discourse.processing.org/t/interstitial-ad/14338/3 "2019-10-01T09:21:23Z")

</div>

Thanks for the reply…after a whole 2 weeks of struggle i ve able to display a interstitial test ad today.Thanks for the concern.BUT i need video ads…i wl post it if i dont succeed.

---

<div class="post-metadata">

**Author:** ![Yash](https://avatars.discourse-cdn.com/v4/letter/y/f17d59/32.png) [@Yash](https://discourse.processing.org/u/Yash)\
**Post date:** [October 1, 2019, 10:26am UTC](https://discourse.processing.org/t/interstitial-ad/14338/4 "2019-10-01T10:26:58Z")

</div>

hi.this produces no error but ad doesnt show.The code is fine but the oncreate method doesnt get called because it is inside a class ,Any Solution?

```auto
import android.os.Looper;//for setup() if needed
import android.os.Bundle;
import android.view.Window;
import android.widget.RelativeLayout;
import android.app.Activity;
//import com.google.ads.*;//
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.MobileAds;
import com.google.android.gms.ads.reward.RewardedVideoAd;
import com.google.android.gms.ads.reward.RewardedVideoAdListener;

    

class Main extends Activity implements RewardedVideoAdListener
{
private RewardedVideoAd mRewardedVideoAd;

@ Override
  public void onCreate(Bundle savedInstanceState) {
  print("on create"); 
  super.onCreate(savedInstanceState);
  Window window = getActivity().getWindow();
  RelativeLayout adsLayout = new RelativeLayout(this);
  RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(
    RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.MATCH_PARENT);
  MobileAds.initialize(this, "ca-app-pub-3940256099942544~3347511713");
    // Use an activity context to get the rewarded video instance.
window.addContentView(adsLayout,lp2);
    mRewardedVideoAd = MobileAds.getRewardedVideoAdInstance(this);
   mRewardedVideoAd.setRewardedVideoAdListener(this);    
    loadRewardedVideoAd();

}
   private void loadRewardedVideoAd() {
    mRewardedVideoAd.loadAd("ca-app-pub-3940256099942544/5224354917",
            new AdRequest.Builder().build());
}

@Override
public void onRewardedVideoAdLoaded() {
if (mRewardedVideoAd.isLoaded()) {
    mRewardedVideoAd.show();
}
}

@Override
public void onRewarded(RewardItem reward) {
    
}

@Override
public void onRewardedVideoAdLeftApplication() {

}

@Override
public void onRewardedVideoAdClosed() {

}

@Override
public void onRewardedVideoAdFailedToLoad(int errorCode) {

}

@Override
public void onRewardedVideoAdOpened() {
   
}

@Override
public void onRewardedVideoStarted() {

}

}

```
