android - Admob Interstitial show before game start -
i want add interstitial ad on game before game starts.
when run app, have 3 diferent game modes when select one, game starts on mode. idea show interstitial after press button, before game starts.
i have followed guide on android developers page, here, doesn't fit need. have modified bit fit code, interstitial not shown before starting game, shown when finish game , returning mainactivity.
this code:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.main); btn1player = (imagebutton) findviewbyid(r.id.oneplayerimgbtn); btnversus = (imagebutton) findviewbyid(r.id.versusimgbtn); btnlocalmultip = (imagebutton) findviewbyid(r.id.lclmultiplayerimgbtn); minterstitialad = new interstitialad(this); minterstitialad.setadunitid(getstring(r.string.ad_intersticial_1_id)); requestnewinterstitial(); btn1player.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { displayinterstitial(); startgame(false,true,mode_single); } }); btnversus.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { displayinterstitial(); startgame(false,true,mode_versus); } }); btnlocalmultip.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { displayinterstitial(); startgame(true,true,mode_localmulti); } }); minterstitialad.setadlistener(new adlistener() { @override public void onadclosed() { requestnewinterstitial(); } }); } private void requestnewinterstitial() { adrequest adrequest = new adrequest.builder().build(); minterstitialad.loadad(adrequest); } public void displayinterstitial() { if (minterstitialad.isloaded()) { minterstitialad.show(); } }
string singlemode ="off"; string versus ="off"; string multi ="off"; btn1player.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { displayinterstitial(); string singlemode ="on"; } }); btnversus.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { displayinterstitial(); string versus ="on"; } }); btnlocalmultip.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { displayinterstitial(); string multi="on"; } }); minterstitialad.setadlistener(new adlistener() { @override public void onadclosed() { if singlemode.equals("on"); {startgame(false,true,mode_single);} if versus.equals("on"); {startgame(false,true,mode_versus);} if multimode.equals("on"); {startgame(true,true,mode_localmulti);} requestnewinterstitial(); } });
Comments
Post a Comment