我已经开发了一个与 StartApp 广告集成的应用程序,用于插页式广告,我想在 onBack Pressed 事件中实现,所以我做了这样的代码..
onCreate 上的代码
int k;
AdRequest adRequest;
private InterstitialAd interstitial;
private StartAppAd startAppAd;
private boolean doubleBackToExitPressedOnce = false;
@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
startAppAd = new StartAppAd(this);
StartAppAd.init(this, "104306606", "204687187");
startAppAd.showAd();
startAppAd.loadAd();
onBack 按下
@Override
public void onBackPressed() {
if (doubleBackToExitPressedOnce) {
startAppAd.onBackPressed();
super.onBackPressed();
return;
}
this.doubleBackToExitPressedOnce = true;
Toast.makeText(this, "Press Again to Exit", Toast.LENGTH_SHORT).show();
}