Search code examples
androidadmobadsinterstitial

Interstitial Ad not loading


Okay this is embarrassing but I have been trying to load interstitial ad and it just does not load and I don't understand why even the logcat does not say anything. I have used the same code in two activities and obviously I am using the tester here. So when I click on the RelativeLayout it displays ad. The problem is it is displaying in one activity perfectly with the tester and does not in the other.

Here is what I tried.

    mInterstitialAd = new InterstitialAd(this);
    mInterstitialAd.setAdUnitId("ad-id");
    mInterstitialAd.loadAd(new AdRequest.Builder().build());
layoutSaved.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            if (mInterstitialAd.isLoaded()) {
                mInterstitialAd.show();
            } else {
                Log.d(TAG, "The interstitial wasn't loaded yet.");
            }
        }
    });

Tried using AdListener to Toast a message to check if it's loaded, and the ad gets loaded but does not open.

P.S: It's worthy to note that I get this error in logcat but everything runs perfectly E/RecyclerView: No adapter attached; skipping layout and I tried these solutions solution 1 and solution 2 but honestly I don't think it will cause any problem (or will it?)


Solution

  • I can't believe this worked after setting my RecyclerView layout_height to "wrap_content".

    So this is what I did in my xml file.

    <android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@id/toolbar">
    

    I was using the layout click listener and this layout was wrapping the RecyclerView and other views. Since it was set to match_parent the layout click was not recognized as recyclerview was filling the layout although it was empty. I believe this could be the issue. Hope it helps someone in future :)