Кто-нибудь знает, как показывать промежуточную рекламу, когда пользователь нажимает кнопку второй раз. Я имею в виду, что когда пользователь нажимает кнопку один раз, реклама не должна появляться, но всякий раз, когда пользователь нажимает эту же кнопку во второй раз, она должна отображаться...
public class MainActivity extends AppCompatActivity {
Toolbar toolbar;
ShowInterstitial showInterstitial;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
showInterstitial = new ShowInterstitial(this);
getSupportActionBar().setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
getSupportActionBar().setCustomView(R.layout.app_bar);
/*toolbar = findViewById(R.id.app_bar);
toolbar.setTitle("hell");
toolbar.*/
}
int counter = 0;
public void onClick(View view) {
if(view.getId() == R.id.ll1 ) {
counter++;
if (counter == 2) {
counter = 0;
Intent intent = new Intent(this, AggregatesActivity.class);
startActivity(intent);
if (showInterstitial != null && ShowInterstitial.isLoaded())
showInterstitial.showInterstitial();
}
}
и ShowInterstitial * Здесь указан код 1005 *, который я вызываю в различных видах деятельности.
public class ShowInterstitial {
private InterstitialAd mInterstitialAd;
private Context context;
private boolean isAddReplace = false;
public ShowInterstitial(Context context) {
this.context = context;
mInterstitialAd = newInterstitialAd(context);
loadInterstitial();
}
private InterstitialAd newInterstitialAd(final Context context) {
InterstitialAd interstitialAd = new InterstitialAd(context);
/*if (!isAddReplace)
interstitialAd.setAdUnitId(context.getString(R.string.interstitial_one));*/
interstitialAd.setAdUnitId(context.getString(R.string.interstitial_one));
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
isAddReplace = !isAddReplace;
}
@Override
public void onAdFailedToLoad(int errorCode) {
}
@Override
public void onAdClosed() {
goToNextLevel();
}
});
return interstitialAd;
}
public boolean showInterstitial() {
if (mInterstitialAd != null && mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
} else {
goToNextLevel();
}
return false;
}
public void loadInterstitial() {
// Disable the next level button and load the ad.
AdRequest adRequest = new AdRequest.Builder()
.setRequestAgent("android_studio:ad_template").build();
mInterstitialAd.loadAd(adRequest);
}
private void goToNextLevel() {
// Show the next level and reload the ad to prepare for the level after.
mInterstitialAd = newInterstitialAd(context);
loadInterstitial();
}
}