0

I am trying to integrate both Chartboost and AdMob interstitials in my game mediated through AdMob. I am also looking to integrate the Chartboost appwall and analytic. For the app-wall and analytic to work, I need CB object outside of AdMob's custom event listener class.

Currently, I my listener activity looks like this.

public class ChartboostAdAdapter  implements CustomEventInterstitial{   
    private Chartboost cb;
    protected static CustomEventInterstitialListener mListener;
    Activity activity;

    @Override
    public void destroy() {
        cb.onDestroy(activity);
    }

    @Override
    public void requestInterstitialAd(CustomEventInterstitialListener customListener, Activity activity,
            String param1, String param2, MediationAdRequest mAdRequest, Object object) {
            mListener = customListener;
            this.activity = activity;
            cb = Chartboost.sharedChartboost();
            cb.cacheInterstitial("Post Game");

    }

    @Override
    public void showInterstitial() {
        cb.showInterstitial();
    }   
}

My Chartboost delegate is defined in a separate file. Declaring CustmEventInterstitialListener as static allows me to access it from CB delegate. While, the setup works, I am concerned about memory leak because of the CustomEventInterstitialListener being declared as static.

I am at loss of ideas over how to use Chartboost appwall, and analytics while mediating the banner. The only alternative I can think of is to use hard coded mediation within the app and sacrifice dynamic reordering through AdMob. Is there no better way?

Update: More information regarding why I need to access the CustomEventInterstitialListener. I need to call methods such as cb.cacheMoreApps() and cb.getAnalytics().trackEvent("Stats") which fall outside the purview of AdMob Mediation. Furthermore, I need to act on didCacheMoreApps so that I can create a custom waterfall for More Apps/App-wall, I have to define the Delegate outside the CustomEventInterstitial class.

As requested, here is the code for CBDelegate:

private ChartboostDelegate cbdelegate = new ChartboostDelegate() {

    final String tag = "CHARTBOOST";
    @Override
    public boolean shouldRequestMoreApps() {
        return true;
    }

    @Override
    public boolean shouldRequestInterstitialsInFirstSession() {
        return true;
    }

    @Override
    public boolean shouldRequestInterstitial(String arg0) {
        return true;
    }

    @Override
    public boolean shouldDisplayMoreApps() {
        return true;
    }

    @Override
    public boolean shouldDisplayLoadingViewForMoreApps() {
        return true;
    }

    @Override
    public boolean shouldDisplayInterstitial(String arg0) {
        return true;
    }

    @Override
    public void didShowMoreApps() {
    }

    @Override
    public void didShowInterstitial(String arg0) {
        if(mAdAdapter !=null) mAdAdapter.mListener.onPresentScreen();
    }

    @Override
    public void didFailToLoadMoreApps() {
        Log.i(tag, "Interstital failed to load more interstital");
    // Waterfall code for More-App/App-wall. Use Ad-Mob Custom event to manage it?
    }

    @Override
    public void didFailToLoadInterstitial(String arg0) {
        if(mAdAdapter !=null) mAdAdapter.mListener.onFailedToReceiveAd();
        Log.i(tag, "Interstital failed to load");
    }

    @Override
    public void didDismissMoreApps() {
        Log.i(tag, "More apps dismissed");
        finish();
    }

    @Override
    public void didDismissInterstitial(String arg0) {
        if(mAdAdapter !=null) mAdAdapter.mListener.onDismissScreen();
        Log.i(tag, "Interstital dismissed");
    }

    @Override
    public void didCloseMoreApps() {
        Log.i(tag, "More appds closed");
        finish();
    }

    @Override
    public void didCloseInterstitial(String arg0) {
        Log.i(tag, "Interstital closed");
        if(mAdAdapter !=null) mAdAdapter.mListener.onDismissScreen();
    }

    @Override
    public void didClickInterstitial(String arg0) {
    }

    @Override
    public void didCacheMoreApps() {
        Log.i(tag, "More apps cached");
    }

    @Override
    public void didCacheInterstitial(String arg0) {
        Log.i(tag, "Interstital cached");
        if(mAdAdapter !=null) mAdAdapter.mListener.onReceivedAd();
    }

    @Override
    public void didFailToLoadUrl(String arg0) {
        Log.i(tag, "Interstital failed to load url");
        if(mAdAdapter !=null) mAdAdapter.mListener.onFailedToReceiveAd();
    }

    @Override
    public void didClickMoreApps() {
    }
};
Puneet
  • 653
  • 1
  • 7
  • 18
  • I don't understand why you need to access the CustomEventInterstitialListener from the CB delegate. If you posted that code it would help. – William Mar 15 '14 at 04:53
  • I need to access the CustomeEventInterstitialListener from CB delegate because I use the CB object for more than just interstitial, i.e. More apps screen and analytics. I can't do that if its initialized only within the CustomeEventInterstitialListener because my activity won't have the CB object reference. I will post the CBDelegate code in a minute. – Puneet Mar 15 '14 at 05:28

1 Answers1

0

ChartBoostDelegate doesn't seem to have dependency on anything other than mAdAdapter which I presume is an instance of ChartboostAdAdapter.

So inject mAdAdapter into ChartBoostDelegate and avoid the static reference.

William
  • 20,150
  • 8
  • 49
  • 91