New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Previous banner is invalidated before the next banner is fully loaded #171

Closed
jhansche opened this Issue Jun 4, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@jhansche

jhansche commented Jun 4, 2015

When a response is received to load a custom event banner, the previous banner is immediately invalidated before the next banner begins to request the next ad:

    protected void loadCustomEvent(String customEventClassName, Map<String, String> serverExtras) {
...
        if (mCustomEventBannerAdapter != null) {
            mCustomEventBannerAdapter.invalidate();
        }

        mCustomEventBannerAdapter = CustomEventBannerAdapterFactory.create( ... );
        mCustomEventBannerAdapter.loadAd();
    }

This results in a blank ad slot for the duration of the new banner's ad load.

I think instead, the old adapter's invalidate() method should be deferred until after the new banner adapter has completely loaded the next ad.

@jhansche

This comment has been minimized.

jhansche commented Jun 4, 2015

I am able to work around this by extending MoPubView:

public class MoPubView2 extends MoPubView {
    private CustomEventBannerAdapter mDeferredBannerAdapter;

    public MoPubView2(Context context) {
        super(context);
    }

    public MoPubView2(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void loadCustomEvent(String customEventClassName, Map<String, String> serverExtras) {
        if (mCustomEventBannerAdapter != null) {
            // the super class will immediately invalidate the current banner,
            // so instead let's override that and defer the invalidate until after the new banner is loaded.
            mDeferredBannerAdapter = mCustomEventBannerAdapter;
            mCustomEventBannerAdapter = null;
            MoPubLog.v("Loading a new banner; invalidation of old banner will be deferred: " + mDeferredBannerAdapter);
        }

        super.loadCustomEvent(customEventClassName, serverExtras);
    }

    @Override
    public void setAdContentView(View view) {
        if (mDeferredBannerAdapter != null && !mDeferredBannerAdapter.isInvalidated()) {
            MoPubLog.v("Deferred banner invalidation is happening now: " + mDeferredBannerAdapter);
            mDeferredBannerAdapter.invalidate();
            mDeferredBannerAdapter = null;
        }

        super.setAdContentView(view);
    }
}
@jhansche

This comment has been minimized.

jhansche commented Jun 5, 2015

I also ended up overriding destroy() in order to invalidate the deferred adapter at that time.

@jhansche

This comment has been minimized.

jhansche commented Jun 5, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment