我正在开发一款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()?
虽然我收到了这个错误,但是显示了添加(我已经在很多设备上对它进行了测试),除了索尼之外,它似乎在所有这些设备中运行良好。
如何改进此代码以在退出时显示插页式广告?
谢谢!
答案 0 :(得分:2)
最后,我发现了一种名为Postitial的新广告技术,当用户以自然方式退出应用时,我会展示mopub全屏广告。您可以在此处查看更多信息:http://iqzone.com/mobile-advertising-solutions/case-studies/
答案 1 :(得分:1)
你在ondestroy上加载插页式广告。当你的活动在插入插页式广告后被破坏时,你就会泄露。在ondestroy中调用interstitial.destroy()。
您可能想要做的是处理onbackpressed。加载插页式oncreate,显示它的onbackpressed并在ondestroy上销毁它。
答案 2 :(得分:1)
旧帖子,但我现在正在寻找这个问题并找到了这篇文章。
现在,如果您收到有关“活动已泄露窗口”的错误,请记得在onAdClosed上放置finish()而不是其他地方
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
finish();
requestNewInterstitial();
}
});
如果您想要关闭活动并显示插页式广告,请执行此操作。
答案 3 :(得分:0)
在onDestroy()中确保你销毁mopubview
if (mMoPubView!=null) {
mMoPubView.destroy();
}
答案 4 :(得分:0)
您可以尝试重载onBackPressed方法。 这样,onDestroy仍可用于清理插页式广告。
在你的活动中
@Override
public void onBackPressed(){
if (interstitial.isReady()) {
interstitial.show(); //this will show the interstitial if it's ready
} else {
super.onBackPressed(); //this will exit the program
}
}
然后在你的监听器调用finish()时返回插页式广告(失败或关闭时)
@Override
public void onInterstitialFailed(MoPubInterstitial interstitial, MoPubErrorCode errorCode) {
finish(); //this will exit the program if interstitial fail to load.
}
@Override
public void onInterstitialDismissed(MoPubInterstitial interstitial) {
finish(); //this will exit the program if interstitial is closed
}
当然你还需要按照正常情况调用destroy。
@Override
protected void onDestroy() {
interstitial.destroy();
super.onDestroy();
}
答案 5 :(得分:0)
100%工作解决方案,我们需要为广告和横幅广告调用销毁功能。
@Override
protected void onDestroy() {
if(mopubInterstitial != null){
mopubInterstitial.destroy();
}
if (mopubBannerPubView != null){
mopubBannerPubView.destroy();
}
super.onDestroy();
}