我正试图在我通过AdMob调解的游戏中整合Chartboost和AdMob插页式广告。我也希望整合Chartboost appwall和analytic。为了使app-wall和analytic能够工作,我需要在AdMob的自定义事件监听器类之外使用CB对象。
目前,我的听众活动看起来像这样。
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();
}
}
我的Chartboost委托是在一个单独的文件中定义的。将CustmEventInterstitialListener声明为static允许我从CB委托访问它。虽然设置有效,但我担心内存泄漏,因为CustomEventInterstitialListener被声明为静态。
我对如何在调解横幅时使用Chartboost appwall和分析失去了想法。我能想到的唯一选择是在应用程序中使用硬编码调解,并通过AdMob牺牲动态重新排序。有没有更好的办法?
更新:有关我需要访问CustomEventInterstitialListener
的原因的详细信息。
我需要调用cb.cacheMoreApps()
和cb.getAnalytics().trackEvent("Stats")
等不属于AdMob Mediation范围的方法。此外,我需要对didCacheMoreApps采取行动,以便为更多应用程序/应用程序墙创建自定义瀑布,我必须在CustomEventInterstitial
类之外定义委托。
根据要求,这是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() {
}
};
答案 0 :(得分:0)
ChartBoostDelegate似乎没有依赖mAdAdapter以外的任何东西,我认为它是ChartboostAdAdapter的一个实例。
因此,将mAdAdapter注入ChartBoostDelegate并避免静态引用。