Help with coding exit Ads

Hi to everyone,
i am a wannabe developer :smiley: and quite unexperienced with programming so maybe this question may seem stupid to many of you, but i have been struggling for days and canā€™t find how to do it.

I managed to setup correctly a unity3d admob plugin (this: https://github.com/nabrozidhs/unity_admob_android) and to get it to work so that it displays the banner only when i want it.

My problem comes with the interstitialā€¦i tested it and it is also working, but i canā€™t find a way to make it appear when the user leave the application, either by pressing the home button (the back button is used to go back to main menu in my game) or by pressing the quit button i provide in the different scenes.

I tried to call the admob.showinterstitial under void onApplicationQuit and also onDestroy and, in both cases, i have the ad correctly appearā€¦ but then it automatically closes up after 1-2s (i imagine as soon as the app is completely closed).
In both cases, also, the interstitial appears only when i use my ingame quit button (which does application.quit) but not when pressing the home button on the phone.

Iā€™ve read many people saying that they use interstitial ads on app exit, so it is doable for sureā€¦but can anyone tell me how to do it please?

your activity can listen for every button pressed.

@Override

public boolean onKeyDown(int keyCode, KeyEvent event) {
if(keyCode == KeyEvent.KEYCODE_BACK){
//do smth
}
else if(keyCode == KeyEvent.KEYCODE_MENU){
//do smth
}
return false;
}

then u display loaded interstial. And close the application only after user close the ap or hit the back button again (hitting back button is easier than clicking X but maybe some ppl will click ad instead. Is it ok guys? )
your interstial has event on Close. Look on example:

public void displayInterstitialAndExit() {

this.runOnUiThread(new Runnable() {
@Override
public void run() {
interstitial.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
super.onAdClosed();
finish();
System.exit(0);
}
});

if (interstitial.isLoaded()) {
interstitial.show();
}
else{
System.out.println(ā€œNo interestitial loadedā€);
finish();
System.exit(0);
}

}
});
}

bad code formating but probably u get the point:)

thx, i will try to do thatā€¦even though it seems the plugin i am using doesnā€™t have a listener, so i guess iā€™ll have to learn how to code my own banners :frowning:

if you use admob and google play sdk you should have the same what i have