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() {
}
};