ljmelgui ljmelgui - 1 month ago 32
Android Question

Android: Show mopub interstitial ad when user exits the app clicking back button

I am developing an android app and would like showing a mopub interstitial full screen ad when user exits the app pressing back button.

I have tried it creating the interstitial ad and displaying it in onDestroy method. Something like that:

@Override
public void onDestroy(){
this.interstitial = new MoPubInterstitial(this, MY_INTERSTITIAL_AD_UNIT_ID_HERE);
this.interstitial.setInterstitialAdListener(this);
this.interstitial.load();

super.onDestroy();
}

// InterstitialAdListener method
@Override
public void onInterstitialLoaded(MoPubInterstitial interstitial) {
if (interstitial.isReady()) {
mInterstitial.show();
} else {
// Other code
}
}


However, I am not destroying interstitial anywhere (mInterstitial.destroy();) since I don't know where can I do it, and therefore I am getting this error:

Activity com.myActivity has leaked IntentReceiver com.mopub.mobileads.MoPubView$1@41baffc0 that was originally registered here. Are you missing a call to unregisterReceiver()?
android.app.IntentReceiverLeaked: Activity com.myActivity has leaked IntentReceiver com.mopub.mobileads.MoPubView$1@41baffc0 that was originally registered here. Are you missing a call to unregisterReceiver()?


Although I am getting this error, the add is shown (I have tested it in many devices) and it seems it works well in all of them except sony.

How could I improve this code to show interstitial on exit??

Thanks!!

Answer

Finally, I found a new ad technology called Postitial that let me show mopub full screen ads when user exits the app in a natural way. You can see more information here: http://iqzone.com/mobile-advertising-solutions/case-studies/