java - How To Display Admob Interstitial Every Time A Button Is Pressed -
i'm beginner when comes android development. first application. know how display admob interstitial ad every time button pressed. have managed display interstitial ad, on first time button pressed. however, getting error when trying load ad. here code:
package com.mycash.borgjake.mycash; import android.content.intent; import android.support.v7.app.appcompatactivity; import android.os.bundle; import android.widget.button; import android.widget.textview; import android.view.view; import com.google.android.gms.ads.adlistener; import com.google.android.gms.ads.adrequest; import com.google.android.gms.ads.adview; import com.google.android.gms.ads.interstitialad; import static com.mycash.borgjake.mycash.r.styleable.view; public class mainactivity extends appcompatactivity { private interstitialad minterstitial; button btnclick; button btnwithdraw; textview txtbalance; @override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_main); adview adview = (adview)findviewbyid(r.id.adview); adrequest adrequest = new adrequest.builder() .addtestdevice(adrequest.device_id_emulator) .build(); adview.loadad(adrequest); btnclick = (button) findviewbyid(r.id.button); txtbalance = (textview) findviewbyid(r.id.textview); btnclick.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { string countvalue = txtbalance.gettext().tostring(); int dblcountvalue = integer.parseint(countvalue); if (minterstitial.isloaded()) { minterstitial.show(); } minterstitial.loadad(request); //<---error dblcountvalue++; txtbalance.settext(string.valueof(dblcountvalue)); } }); minterstitial = new interstitialad(this); minterstitial.setadunitid("ca-app-pub-2245289628812463/9905502438"); adrequest request = new adrequest.builder() .addtestdevice(adrequest.device_id_emulator) .build(); minterstitial.loadad(request); } public void onbuttonclick(view v) { if(v.getid() == r.id.button2) { intent = new intent(mainactivity.this, withdraw.class); startactivity(i); } } }
thanks in advance. :)
you dont have call function minterstitial.loadad(request);
every time
or if want call call
minterstitial.loadad(request); if (minterstitial.isloaded()) { minterstitial.show(); }
or remove minterstitial.loadad(request);
every time click button .
Comments
Post a Comment