Android:当用户单击后退按钮退出应用程序时显示 mopub 插页式广告

标签 android exit mopub interstitial

我正在开发一个 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/

相关文章:

ios - 如何禁用 MoPub AdPlacer

java - MapView 上的多边形数组

c# - 如何在 WPF 中使用 Application.Exit 事件?

ios - 需要通过 MoPub 展示 Admob 广告

Ruby - 忽略代码中的 "exit"

c - 从由同一脚本编译的 C 程序中退出 shell 脚本

ios - 在 iOS 上将 editActionsForRowAtIndexPath 与 MoPub 结合使用

java - retrofit 时禁用 SPDY 连接

android - 从反射(reflect)在先前创建的 Activity 中的 Activity 更改语言

android - 实时播放来自麦克风的声音