These days I am doing a test, the objective is to click on a button to go to activity2 and show the interstitial advertising. For now this is the result thanks to information from: link
The problem:
Upon returning to the main page (MainActivity), I pressed the button to re-enter activity2 and it is no longer displayed. Only if I close the application and open the application and press the activity button 2 the advertising is displayed.
MainActivity code
public class MainActivity extends Activity {
private InterstitialAd mInterstitialAd;
private static final String TAG = "InfoApp";
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
//***** Initialize the Mobile Ads SDK.*********** -//
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
}
});
//**********************************************************//
adrequest_interstitial = new AdRequest.Builder().build();
InterstitialAd.load(this,ConfigPubli.Ads_interstitial, adrequest_interstitial,
new InterstitialAdLoadCallback()
{
#Override
public void onAdLoaded(#NonNull InterstitialAd interstitialAd)
{
mInterstitialAd = interstitialAd;
Log.i(TAG, "onAdLoaded");
}
#Override
public void onAdFailedToLoad(#NonNull LoadAdError loadAdError)
{
// Handle the error
Log.i(TAG, loadAdError.getMessage());
mInterstitialAd = null;
}
});
}
public void adstot(Intent i){
mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback() {
#Override
public void onAdDismissedFullScreenContent() {
mInterstitialAd = null;
startActivity(i);
}
#Override
public void onAdFailedToShowFullScreenContent(#NonNull AdError adError) {
mInterstitialAd = null;
startActivity(i);
}
});
}
public void page2(View view){ //button
Intent i = new Intent (this, Activity2.class);
i.putExtra("valor","page2");
int randomAd = (int)(Math.random()*10);
if (mInterstitialAd != null && randomAd<=1) {
adstot(i);
mInterstitialAd.show(this);
}
else{
startActivity(i);
}
}
}
Thanks for the answers
Whenever InterstitialAd has been shown, the variable mInterstitialAd was set to null. So, how mInterstitialAd can be shown twice?
You should make a new request to get an interstitial just after mInterstitialAd = null;
Try like below:
public class MainActivity extends Activity {
private InterstitialAd mInterstitialAd;
private static final String TAG = "InfoApp";
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
//***** Initialize the Mobile Ads SDK.*********** -//
MobileAds.initialize(this, new OnInitializationCompleteListener() {
#Override
public void onInitializationComplete(InitializationStatus initializationStatus) {
// Initialization complete
// You are now free to make an ad request
loadAnInterstitial();
}
});
//**********************************************************//
}
private void loadAnInterstitial(){
adrequest_interstitial = new AdRequest.Builder().build();
InterstitialAd.load(this,ConfigPubli.Ads_interstitial, adrequest_interstitial,
new InterstitialAdLoadCallback()
{
#Override
public void onAdLoaded(#NonNull InterstitialAd interstitialAd)
{
mInterstitialAd = interstitialAd;
Log.i(TAG, "onAdLoaded");
}
#Override
public void onAdFailedToLoad(#NonNull LoadAdError loadAdError)
{
// Handle the error
Log.i(TAG, loadAdError.getMessage());
mInterstitialAd = null;
}
});
}
public void adstot(Intent i){
mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback() {
#Override
public void onAdDismissedFullScreenContent() {
mInterstitialAd = null;
startActivity(i);
// make a new ad request here
loadAnInterstitial();
}
#Override
public void onAdFailedToShowFullScreenContent(#NonNull AdError adError) {
mInterstitialAd = null;
startActivity(i);
// make a new ad request here
loadAnInterstitial();
}
});
}
public void page2(View view){ //button
Intent i = new Intent (this, Activity2.class);
i.putExtra("valor","page2");
int randomAd = (int)(Math.random()*10);
if (mInterstitialAd != null && randomAd<=1) {
adstot(i);
mInterstitialAd.show(this);
}
else{
startActivity(i);
// make a new ad request here
loadAnInterstitial();
}
}
}
That's all. Hope it will help.
Updated code (another version):
I have added an (if), after 6 clicks of the button it will load a new ad.
public void page2(View view){ //button
Intent i = new Intent (this, Activity2.class);
i.putExtra("valor","page2");
int randomAd = (int)(Math.random()*10);
if (mInterstitialAd != null && randomAd<=1) {
adstot(i);
mInterstitialAd.show(this);
}
else{
startActivity(i);
if(countclick==6)
{
loadAnInterstitial();
}else{
countclick=countclick+1;
}
}
}
It works!, I hope that google admob does not consider that it is poorly implemented.
Related
I am using new Handler().postDelayed to set a delay when reloading an ad when the previous request of the ad has failed in the requestNewInterstitial method. I am wondering if invoking/creating many new Handlers would be okay as in my loop the new Handler line of code could be run up to 5 times. My question is, if later I have to clear the handler in the Activity onDestroy method so that there are no memory leaks, should I clear it only once or should I clean all the new Handlers I have created (the number of times that the loop is run). Also, how could I implement to clear the Handler OnDestroy method?
This is my code:
#Override
protected void onResume() {
super.onResume();
requestNewInterstitial(5);
}
private void requestNewInterstitial(int maxRetry) {
AdRequest adRequest = new AdRequest.Builder().build();
InterstitialAd.load(Activityone.this, getString(R.string.interid),
adRequest, new InterstitialAdLoadCallback() {
#Override
public void onAdLoaded(#NonNull InterstitialAd interstitialAd) {
mInterstitialAd = interstitialAd;
}
#Override
public void onAdFailedToLoad(#NonNull LoadAdError loadAdError) {
if (maxRetry>0){
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
mInterstitialAd = null;
requestNewInterstitial(maxRetry-1);
}
}, 1000);
}
});
}
}
btnPause.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (mInterstitialAd != null) {
mInterstitialAd.show(Activityone.this);
mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback() {
#Override
public void onAdDismissedFullScreenContent() {
}
#Override
public void onAdFailedToShowFullScreenContent(#NonNull AdError adError) {
}
});
Thanks for the help.
If the delay in postDelay extends beyound the activity lifetime, the runnable will execute after the activity has been destryed and will lead app crash. You should use a common handler. To clear the handler, you can call handler.removeCallbacksAndMessages(null); in on destroy or wherever else you want to clear them.
Handler handler;
#Override
public void onCreate(#Nullable Bundle savedInstanceState, #Nullable PersistableBundle persistentState) {
super.onCreate(savedInstanceState, persistentState);
handler = new Handler();
btnPause.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (mInterstitialAd != null) {
mInterstitialAd.show(Activityone.this);
mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback() {
#Override
public void onAdDismissedFullScreenContent() {
}
#Override
public void onAdFailedToShowFullScreenContent(#NonNull AdError adError) {
}
});
}
}
});
}
#Override
protected void onResume() {
super.onResume();
requestNewInterstitial(5);
}
#Override
protected void onDestroy() {
handler.removeCallbacksAndMessages(null)
super.onDestroy();
}
private void requestNewInterstitial(int maxRetry) {
AdRequest adRequest = new AdRequest.Builder().build();
InterstitialAd.load(Activityone.this, getString(R.string.interid), adRequest, new InterstitialAdLoadCallback() {
#Override
public void onAdLoaded(#NonNull InterstitialAd interstitialAd) {
mInterstitialAd = interstitialAd;
}
#Override
public void onAdFailedToLoad(#NonNull LoadAdError loadAdError) {
if (maxRetry > 0) {
handler.postDelayed(new Runnable() {
#Override
public void run() {
mInterstitialAd = null;
requestNewInterstitial(maxRetry - 1);
}
}, 1000);
}
}
});
}
I have created a function to show interstitial ad before showing another activity.
It's working but onAdDismissedFullScreenContent is being called 2-3 sec lately after closing the ad. It causes previous screen to stand-by.
There's a chance to re-click the button to show the wanted Activity.
I really don't understand how to resolve this issue.
Here is my code:
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
AdManager.showInterstitial(MainActivity.this, () -> {
Intent i = new Intent(MainActivity.this, MainActivity2.class);
startActivity(i);
});
}
});
AdManager.loadInterstitial(this);
}
}
And this is Application Class:
public class App extends Application {
private static Context mContext;
#Override
public void onCreate() {
super.onCreate();
mContext = getApplicationContext();
AdManager.Init(this);
}
public static Context getContext() {
return mContext;
}
}
AdManager Class:
public class AdManager {
private static InterstitialAd mInterstitialAd;
private static boolean loading, showing;
public static void Init(Context context) {
MobileAds.initialize(context, initializationStatus -> {
loadInterstitial(context);
});
}
public static void loadInterstitial(Context context) {
if (context == null)
context = App.getContext();
Context finalContext = context;
if (mInterstitialAd != null) {
Toast.makeText(context,"already loaded",Toast.LENGTH_LONG).show();
return;
}
if (loading) {
Toast.makeText(context,"already another request is processing",Toast.LENGTH_LONG).show();
return;
}
Toast.makeText(context,"requesting interstitial",Toast.LENGTH_LONG).show();
loading = true;
AdRequest adRequest = new AdRequest.Builder().build();
InterstitialAd.load(context, "Interstial Ad Unit ID", adRequest, new InterstitialAdLoadCallback() {
#Override
public void onAdLoaded(#NonNull InterstitialAd interstitialAd) {
mInterstitialAd = interstitialAd;
Toast.makeText(finalContext,"ad loaded",Toast.LENGTH_LONG).show();
loading = false;
}
#Override
public void onAdFailedToLoad(#NonNull LoadAdError loadAdError) {
mInterstitialAd = null;
loading = false;
Toast.makeText(finalContext,"ad failed to load",Toast.LENGTH_LONG).show();
}
});
}
public static void showInterstitial(Activity activity, #NonNull AdListener listener) {
if (showing) {
Toast.makeText(activity,"already showing",Toast.LENGTH_LONG).show();
listener.onCompleted();
return;
}
if (mInterstitialAd != null) {
showNow(activity, listener);
} else {
Toast.makeText(activity,"mInterstitialAd is null",Toast.LENGTH_LONG).show();
listener.onCompleted();
loadInterstitial(activity.getApplicationContext());
}
}
private static void showNow(Activity activity, AdListener listener) {
if (mInterstitialAd != null && !showing) {
showing = true;
mInterstitialAd.setFullScreenContentCallback(new FullScreenContentCallback() {
#Override
public void onAdDismissedFullScreenContent() {
Toast.makeText(activity,"Ad dismissed",Toast.LENGTH_LONG).show();
mInterstitialAd = null;
listener.onCompleted();
showing = false;
// times to load an new interstitial ad content
loadInterstitial(activity.getApplicationContext());
}
#Override
public void onAdFailedToShowFullScreenContent(#NonNull AdError adError) {
Toast.makeText(activity,"AdFailedToShowFullScreenContent",Toast.LENGTH_LONG).show();
mInterstitialAd = null;
listener.onCompleted();
showing = false;
// times to load an new interstitial ad content
loadInterstitial(activity.getApplicationContext());
}
});
// Now show the ad
Toast.makeText(activity,"call to show ad",Toast.LENGTH_LONG).show();
mInterstitialAd.show(activity);
} else {
Toast.makeText(activity,"either mInterstitialAd is null or ad already is showing",Toast.LENGTH_LONG).show();
listener.onCompleted();
}
}
public interface AdListener {
void onCompleted();
}
}
Please help.
The delay problem
You can't really help it. The problem is from the admob. This will happen. But, to know more about it, we can post an issue abt that on the Google Issue Tracker.
The button problem
I dont think this is any hard task. Just follow the steps:
Create a ProgressBar in your xml layout on top of the button and set its visibility to gone
When the button is click and the ad is shown, you can set the button to invisible and the progress bar can be set to invisible.
Then after a delay, the other activity opens without any harm to the activity from NullPointerException
I am trying to add Facebook Ads(sdk 6.3.0) in my Android App
The documentation on which I base myself
https://developers.facebook.com/docs/audience-network/reference/android/com/facebook/ads/interstitialad.html/?version=v6.3.0
https://developers.facebook.com/docs/audience-network/setting-up/ad-setup/android/interstitial/
I want when the person clicks on a button it shows an ad and then a new activity when the ad end
I also use a return which directly shows the activity if no ads are available
Here are the errors I am getting
The onInterstitialDisplayed method must not be replaced by the superclass
The onInterstitialDismissed method must not be replaced by the superclass
The onError method must not be replaced by the superclass
The onAdLoaded method must not be replaced by the superclass
The onAdClicked method must not be replaced by the superclass
The onAdLoaded method must not be replaced by the superclass
What I have done
private InterstitialAd mInterstitialAd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AudienceNetworkAds.initialize(this);
loadAd();
clickListener();
}
private void clickListener() {
dailyCheck.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
showInterstitialAd(1);
}
});
rewardCheck.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
showInterstitialAd(2);
}
});
}
private void loadAd(){
mInterstitialAd = new InterstitialAd(this, "750944672287722_755093405206182");
}
private void showInterstitialAd(final int i) {
if (mInterstitialAd.isAdLoaded()) {
mInterstitialAd.show();
mInterstitialAd.loadAd(new InterstitialAd.InterstitialLoadAdConfig() {
#Override
public void onInterstitialDisplayed(Ad ad) {
}
#Override
public void onInterstitialDismissed(Ad ad) {
if (i == 1)
{
dailyCheck();
}
if (i == 2)
{
startActivity(new Intent(MainActivity.this, RewardActivity.class));
}
}
#Override
public void onError(Ad ad, AdError adError) {
}
#Override
public void onAdLoaded(Ad ad) {
}
#Override
public void onAdClicked(Ad ad) {
}
#Override
public void onLoggingImpression(Ad ad) {
}
});
return;
}
if (i == 1)
{
dailyCheck();
}
if (i == 2)
{
startActivity(new Intent(MainActivity.this, RewardActivity.class));
}
}
Any help is good to take!
Thank you
I am new to android development and using shared preferences to show ads after a number of buttons clicks. I have several buttons(Like the example below) each with a different intent. What would be the best implementation for my single logic below so that my code is DRY(Don't Repeat Yourself) for all other buttons with different intent.
My Adapter class extends RecyclerView
public class ImageAdaptor extends RecyclerView.Adapter<ImageAdaptor.MyViewHolder> {
#####################################
######################################
########################################
public class MyViewHolder extends RecyclerView.ViewHolder {
public MyViewHolder(View v) {
MobileAds.initialize(acontext, "ca-app-pub-3940256099942544~3347511713");
final InterstitialAd mInterstitialAd = new InterstitialAd(acontext);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
//Here is my working example on first button
//I want to achieve something like this on other clicks with different intents
//I don't want to repeat the logic over and over again
**Button1**.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final ModelStatus modelStatus = arrayList.get(getAdapterPosition());
final Intent intent = new Intent(acontext, Activity1.class);
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdClosed() {
acontext.startActivity(intent);
}
});
SharedPreferences preferences = acontext.getSharedPreferences("PREFRENCE",
Context.MODE_PRIVATE);
int clickCount = preferences.getInt("KEY_CLICK_COUNT", 1);
if (clickCount % 6 == 0) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
acontext.startActivity(intent);
};
}else {
acontext.startActivity(intent);
}
clickCount++;
preferences.edit().putInt("KEY_CLICK_COUNT", clickCount).apply();
}
});
**Button2**.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final Intent intent = new Intent(acontext, Activity2.class);
//Some code with an intent
// I want my logic to go in here for 5 clicks per ad.
// I don't want to repeat myself since i have several such
//buttons with a different intent
}
});
}
}
As easy as pie
public void handleClick(Class destination, int buttonType){
final ModelStatus modelStatus = arrayList.get(getAdapterPosition());
final Intent intent = new Intent(getAppContext(), destination);
mInterstitialAd.setAdListener(new AdListener() {
#Override
public void onAdClosed() {
acontext.startActivity(intent);
}
});
SharedPreferences preferences = acontext.getSharedPreferences("PREFRENCE",
Context.MODE_PRIVATE);
int clickCount = preferences.getInt("KEY_CLICK_COUNT"+buttonType, 1);
if (clickCount % 6 == 0) {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
acontext.startActivity(intent);
};
}else {
acontext.startActivity(intent);
}
clickCount++;
preferences.edit().putInt("KEY_CLICK_COUNT"+buttonType, clickCount).apply();
}
Button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
handleClick(Activity1.class, 1);
}
Button1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
handleClick(Whatever.class, 2);
}
Hi i integrated an admob banner in my game via xml but it not showing in the bottom of my screen the layout of banner already appear in graphical layout ..
Also when i check my logCat i saw this message "Ad is not visible. Not refreshing ad."
I used this code on my name combiner website.
this is my code java
public class FlyingPanda extends Activity{
/** Called when the activity is first created. */
public static FlyingPanda app;
public static CCGLSurfaceView mGLSurfaceView;
private boolean isCreated = false;
private static final String AD_INTERSTITIAL_UNIT_ID = "df2cce209f194168";
/** The interstitial ad. */
private InterstitialAd interstitialAd;
private AdView adView = null;
#Override
public void onCreate(Bundle savedInstanceState) {
if( !isCreated ){
isCreated = true;
} else {
return;
}
app = this;
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
//my code
setContentView(R.layout.adview);
//my code
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
//my code
AdView mAdView = (AdView) findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
mAdView.loadAd(adRequest);
//my code
RelativeLayout layout = new RelativeLayout(this);
layout.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
mGLSurfaceView = new CCGLSurfaceView(this);
layout.addView(mGLSurfaceView);
setContentView(layout);
// Create an ad request. Check logcat output for the hashed device ID to
// get test ads on a physical device.
//AdRequest adRequest = new AdRequest.Builder().build();
//adView.loadAd(adRequest);
//-----------------------------------------------------Interstitial Add
// Create an Interstitial ad.
interstitialAd = new InterstitialAd(this);
interstitialAd.setAdUnitId(AD_INTERSTITIAL_UNIT_ID);
// Load the interstitial ad.
AdRequest interstitialAdRequest = new AdRequest.Builder().build();
interstitialAd.loadAd(interstitialAdRequest);
/////////////////////////////////////////////////////////////////////////////
Common.game_initialize();
getScaledCoordinate();
CCDirector.sharedDirector().attachInView(mGLSurfaceView);
// attach the OpenGL view to a window
Common.sound_engine = SoundEngine.sharedEngine();
loadSound();
CCScene scene = CCScene.node();
scene.addChild(new HelloWorldLayer(), 1);
CCDirector.sharedDirector().runWithScene(scene);
}
#Override
public void onStart() {
super.onStart();
}
#Override
public void onPause() {
if (adView != null) {
adView.pause();
}
super.onPause();
MediaGlobal._shared().pauseMusic();
if(GameLayer.sharedGameLayer() != null){
GameLayer.sharedGameLayer().onPause(null);
}
CCDirector.sharedDirector().pause();
}
#Override
public void onResume() {
super.onResume();
if (adView != null) {
adView.resume();
}
MediaGlobal._shared().resumeMusic();
}
#Override
public void onDestroy() {
if (adView != null) {
adView.destroy();
}
isCreated = false;
MediaGlobal._shared().stopMusic();
Common.sound_engine.realesAllEffects();
super.onDestroy();
CCDirector.sharedDirector().end();
CCTextureCache.sharedTextureCache().removeAllTextures();
CCTextureCache.sharedTextureCache().removeAllTextures();
CCSpriteFrameCache.sharedSpriteFrameCache().removeAllSpriteFrames();
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK){
exitGameDialog();
return false;
}
return super.onKeyDown(keyCode, event);
}
public void exitGameDialog() {
Builder builder = new AlertDialog.Builder(FlyingPanda.this)
.setIcon(R.drawable.icon)
.setTitle("Quitter le jeu?")
.setMessage("Est-vous sûr?")
.setNegativeButton("Non", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int whichButton) {
}
})
.setPositiveButton("Oui",
new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog,
int whichButton) {
CCActionManager.sharedManager()
.removeAllActions();
CCDirector.sharedDirector().end();
finish();
}
});
builder.create().show();
}
private void loadSound() {
SoundEngine.purgeSharedEngine();
Common.sound_engine.preloadEffect(CCDirector.sharedDirector().getActivity().getApplication(), R.raw.bomb);
Common.sound_engine.preloadEffect(CCDirector.sharedDirector().getActivity().getApplication(), R.raw.bounce);
Common.sound_engine.preloadEffect(CCDirector.sharedDirector().getActivity().getApplication(), R.raw.death);
Common.sound_engine.preloadEffect(CCDirector.sharedDirector().getActivity().getApplication(), R.raw.fly);
Common.sound_engine.preloadEffect(CCDirector.sharedDirector().getActivity().getApplication(), R.raw.gamebg);
Common.sound_engine.preloadEffect(CCDirector.sharedDirector().getActivity().getApplication(), R.raw.gameover);
Common.sound_engine.preloadEffect(CCDirector.sharedDirector().getActivity().getApplication(), R.raw.jumppad);
}
private void getScaledCoordinate() {
DisplayMetrics displayMetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
Common.SCREEN_WIDTH = displayMetrics.widthPixels;
Common.SCREEN_HEIGHT = displayMetrics.heightPixels;
Common.kXForIPhone = Common.SCREEN_WIDTH / 480.0f;
Common.kYForIPhone = Common.SCREEN_HEIGHT / 320.0f;
}
// Admob Setting
////////////////////////////////////////////////////////////////////////////////
public void setHideAdView(final boolean bHide) {
runOnUiThread(new Runnable() {
public void run() {
if(bHide) {
adView.setVisibility(View.INVISIBLE);
}
else {
adView.setVisibility(View.VISIBLE);
}
}
});
}
public void showInterstitialAds()
{
runOnUiThread(new Runnable() {
public void run() {
// Load the interstitial ad.
AdRequest interstitialAdRequest = new AdRequest.Builder().build();
interstitialAd.loadAd(interstitialAdRequest);
interstitialAd.show();
}
});
}
}
and this is my xml code
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:layout_height="match_parent"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="0dp"
android:paddingBottom="0dp"
tools:context="com.ideanetstudio.IncroyableAventuresAlaadin.FlayingPanda">
<com.google.android.gms.ads.AdView
android:id="#+id/adView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
ads:adSize="BANNER"
ads:adUnitId="ca-app-pub-848493934849303/736373839303">
</com.google.android.gms.ads.AdView>
add adView.pause(); in onPause() and adView.resume(); in onResume() method:
#Override
protected void onPause() {
adView.pause();
super.onPause();
}
#Override
protected void onResume() {
super.onResume();
adView.resume();
}