我正在开发一个 Android 应用程序,希望在用户按后退按钮退出应用程序时显示 mopub 插页式全屏广告。
我尝试过创建插页式广告并在 onDestroy 方法中显示它。类似这样的事情:
@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
}
}
但是,我不会在任何地方销毁插页式广告 (mInterstitial.destroy();),因为我不知道在哪里可以做到这一点,因此我收到此错误:
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()?
虽然我收到此错误,但已显示添加(我已在许多设备中测试过它),并且似乎它在除索尼之外的所有设备中都运行良好。
如何改进此代码以在退出时显示插页式广告?
谢谢!!
最佳答案
您在 ondestroy 时加载插页式广告。当您的 Activity 在间隙负载后被破坏时,您就会泄漏。在 ondestroy 中调用 interstitial.destroy()。
您可能想要做的是处理 onbackpressed。在create时加载插页式广告,在backpressed时显示它并在destroy时销毁它。
关于Android:当用户单击后退按钮退出应用程序时显示 mopub 插页式广告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17567398/