1

I am working with frame animations and i implement banner and interstitial ads in my activity, but when i do that it slows my application.

Here is my code:

private InterstitialAd interstitial;

interstitial = new InterstitialAd(MainActivity.this);
// Insert the Ad Unit ID
interstitial.setAdUnitId("UNIT ID");

//Locate the Banner Ad in activity_main.xml
AdView adView = (AdView) this.findViewById(R.id.adView);

// Request for Ads
AdRequest adRequest = new AdRequest.Builder()

// Add a test device to show Test Ads
 .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
 .addTestDevice("CC5F2C72DF2B356BBF0DA198")
        .build();

// Load ads into Banner Ads
adView.loadAd(adRequest);

// Load ads into Interstitial Ads
interstitial.loadAd(adRequest);

// Prepare an Interstitial Ad Listener
interstitial.setAdListener(new AdListener() {
    public void onAdLoaded() {
        // Call displayInterstitial() function
        displayInterstitial();
    }
});

}

Any solutions on how to efficiently integrate admob in my class.

Aleem Ahmed
  • 61
  • 1
  • 9
  • you can also use threads to load your requests. once loaded call displayInterstitial method from runonuithread method – Amrut Bidri Mar 14 '15 at 11:50
  • This topic http://stackoverflow.com/questions/14584002/android-admob-memory-usage is quite old but you may find some useful points in admob logic. I am also afraid that some of the suggested solutions may not work fine in Android 4+ devices. – madlymad Mar 14 '15 at 13:00

1 Answers1

0

Answere to your comment

can i put all my admob code in someother class and initialize it in my Main Activity?

Yes, For example: AdMob.java class:

import android.content.Context;

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;

public class AdMob {


    private InterstitialAd interstitial;

    public void displayInterstitial() {
        // If Ads are loaded, show Interstitial else show nothing.
        if (interstitial.isLoaded()) {
        interstitial.show();
        }
        }

    void LoadInterstitialAd(Context ctx){
        // Prepare the Interstitial Ad
        interstitial = new InterstitialAd(ctx);
        // Insert the Ad Unit ID
        interstitial.setAdUnitId("unit_id");



        // Request for Ads
        AdRequest adRequest = new AdRequest.Builder()

        // Add a test device to show Test Ads
        //.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
        //.addTestDevice("CC5F2C72DF2B356BBF0DA198")
        .build();

        // Load ads into Interstitial Ads
        interstitial.loadAd(adRequest);

        // Prepare an Interstitial Ad Listener
        interstitial.setAdListener(new AdListener() {
        public void onAdLoaded() {
        // Call displayInterstitial() function
        displayInterstitial();
        }
        });


    }




}

You can use it anywhere by doing this:

AdMob adMob = new AdMob();
adMob.LoadInterstitialAd(getApplicationContext());

I have only showed for interstitial ad, but it can be done for other ads too..

Jahid
  • 21,542
  • 10
  • 90
  • 108