我在Android上使用SDL2项目。我尝试在输入上创建小横幅,它的工作原理。但我需要在退出时显示全屏广告。我尝试了不同的时间,但iterstitial广告随时都可以使用。我的测试代码,但它不起作用:
protected void onCreate(Bundle savedInstanceState) {
//Log.v("SDL", "onCreate()");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(MY_AD_UNIT_ID);
AdRequest adRequest = new AdRequest.Builder().build();
interstitial.loadAd(adRequest);
// So we can call stuff from static callbacks
mSingleton = this;
// Set up the surface
mEGLSurface = EGL10.EGL_NO_SURFACE;
mSurface = new SDLSurface(getApplication());
mLayout = new AbsoluteLayout(this);
mLayout.addView(mSurface);
setContentView(mLayout);
}
protected void onDestroy() {
if(interstitial.isLoaded()) {
interstitial.show();
}
super.onDestroy();
Log.v("SDL", "onDestroy()");
// Send a quit message to the application
SDLActivity.nativeQuit();
// Now wait for the SDL thread to quit
if (mSDLThread != null) {
try {
mSDLThread.join();
} catch(Exception e) {
Log.v("SDL", "Problem stopping thread: " + e);
}
mSDLThread = null;
//Log.v("SDL", "Finished waiting for SDL thread");
}
}
答案 0 :(得分:4)
试试这个
mInterstitial = new InterstitialAd(this);
mInterstitial.setAdUnitId(getResources().getString(R.string.publisher));
mInterstitial.loadAd(new AdRequest.Builder().build());
答案 1 :(得分:0)
好的,我部分解决了这个问题,我添加了测试设备并且可以正常工作。