0
votes

I have an unpublished Android app that I have inserted interstitial ads into using the AdMob Interstitial Guide and the ads did not initially show. So, thereafter I referenced Admob interstitial ad won't display and I added this:

interstitial.setAdListener(new AdListener(){
          @Override
          public void onAdLoaded(){
               displayInterstitial();
          }
});

Instead of just loading the add using displayInterstitial(). After doing this it still will not show the ads. Then I referenced "Because Admob interstitial ads won't display" and that did not help because I had already added .Builder().build() to the new AdRequest.

Afterwards I referenced "How to show interstitial ads?" and that was not useful because I am testing on a real device and not an emulator, and it also just repeated what the Google Interstitial Guide (first link) showed me how to do. Then I finally looked at Interstitial Ad's Listener's onAdLoaded() won't run and I added the Internet permission in my manifest (I had already added the meta-data property to my manifest as a child of application) and tried this code to show the ad:

interstitial.setAdListener(new AdListener() {
    @Override
    public void onAdLoaded() {
        // TODO Auto-generated method stub
        super.onAdLoaded();
        interstitial.show();
    }
});

And that did not work either.

I have 2 activities using ads (the app has a MainActivity, a GameScreen activity, and a Redirect activity)

Here is the MainActivity (I have excluded all the code except the ad involved code):

    public class MainActivity extends ActionBarActivity {

    private InterstitialAd interstitial;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



        // Create the interstitial.
        interstitial = new InterstitialAd(this);
        interstitial.setAdUnitId("ca-app-pub-3171635XXXXXXXXX/XXXXXXXXXX");
        // Create ad request.
        AdRequest adRequest = new AdRequest.Builder().build();
        // Begin loading your interstitial.
        interstitial.loadAd(adRequest);

        interstitial.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                super.onAdLoaded();
                interstitial.show();
            }
        });

    }

    // Invoke displayInterstitial() when you are ready to display an interstitial.
    public void displayInterstitial() {
        if (interstitial.isLoaded()) {
            interstitial.show();
        }
    }


}

Here is the Redirect activity (I have excluded all the code except the ad involved code, identical to the MainActivity's ad showing code):

public class Redirect extends ActionBarActivity {


private InterstitialAd interstitial;


@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_redirect);


    // Create the interstitial.
    interstitial = new InterstitialAd(this);
    interstitial.setAdUnitId("ca-app-pub-317163XXXXXXXXXX/XXXXXXXXXX");
    // Create ad request.
    AdRequest adRequest = new AdRequest.Builder().build();
    // Begin loading your interstitial.
    interstitial.loadAd(adRequest);

    interstitial.setAdListener(new AdListener(){
        @Override
        public void onAdLoaded(){
            super.onAdLoaded();
            interstitial.show();
        }
    });       

}    

// Invoke displayInterstitial() when you are ready to display an interstitial.
public void displayInterstitial() {
    if (interstitial.isLoaded()) {
        interstitial.show();
    }
}

}

Here is my Manifest:

<?xml version="1.0" encoding="utf-8"?>

<uses-permission android:name="android.permission.INTERNET"/>

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <meta-data android:name="com.google.android.gms.version"
               android:value="@integer/google_play_services_version" />
    <activity
        android:name=".UI.MainActivity"
        android:label="@string/app_name"
        android:screenOrientation="landscape" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity
        android:name=".UI.GameScreen"
        android:label="@string/title_activity_game_screen"
        android:screenOrientation="landscape"
        android:parentActivityName=".UI.MainActivity" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="benyamephrem.tilt.UI.MainActivity" />
    </activity>
    <activity
        android:name=".UI.Redirect"
        android:label="@string/title_activity_redirect"
        android:screenOrientation="landscape"
        android:parentActivityName=".UI.GameScreen" >
        <meta-data
            android:name="android.support.PARENT_ACTIVITY"
            android:value="benyamephrem.tilt.UI.GameScreen" />
    </activity>
</application>

I have heavily researched this and I haven't come up with any solution that has worked. I feel like I'm missing some small detail but I can't currently see why this is not working.

Any help appreciated!

1
Where is your admob activity in the manifest? The one that goes <activity android:name="com.google.android.gms.ads.AdActivity"...Reuben L.
@ R.L. Oh my! HOW COULD I HAVE MISSED THAT! I just added that and now the ads display but I'll have to adjust them around...THANK YOU! Should I provide an answer to my own question including what I added in my manifest?Benyam Ephrem
Let me add the answer? hahaReuben L.

1 Answers

1
votes

You are missing the following activity in your manifest:

<!--Include the AdActivity configChanges and theme. -->
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:theme="@android:style/Theme.Translucent" />