Я написал код для показа промежуточной рекламы в моем приложении для Android.Работает нормально, но проблема в том, что реклама так часто появляется.В чем может быть проблема??Это так же, как пользователь будет видеть рекламу слишком часто?
MainActivity
public class MainActivity extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener {
private ViewPager viewPager;
private DrawerLayout drawer;
private TabLayout tabLayout;
private String[] pageTitle = {"fragment1", "fragment2","Fragment3"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
InterstitialAd mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId(getResources().getString(R.string.admob_interstitial_id));
AdRequest adRequestInter = new AdRequest.Builder().build();
mInterstitialAd.setAdListener(new AdListener() {
@Override
public void onAdLoaded() {
mInterstitialAd.show();
}
@Override
public void onAdClosed()
{
AdRequest adRequest = new AdRequest.Builder()
.build();
mInterstitialAd.loadAd(adRequest);
}
});
mInterstitialAd.loadAd(adRequestInter);
viewPager = (ViewPager) findViewById(R.id.view_pager);
viewPager.setOffscreenPageLimit(3);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
drawer = (DrawerLayout) findViewById(R.id.drawerLayout);
setSupportActionBar(toolbar);
AppRate.with(this)
.setInstallDays(0)
.setLaunchTimes(3)
.setRemindInterval(2)
.monitor();
AppRate.showRateDialogIfMeetsConditions(this);
AppRate.with(this).clearAgreeShowDialog();
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar,
R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
tabLayout = (TabLayout) findViewById(R.id.tab_layout);
for (int i = 0; i < 3; i++) {
tabLayout.addTab(tabLayout.newTab().setText(pageTitle[i]));
}
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
assert navigationView != null;
navigationView.setNavigationItemSelectedListener(this);
navigationView.setItemIconTintList(null);
ViewPagerAdapter pagerAdapter = new ViewPagerAdapter(getSupportFragmentManager());
viewPager.setAdapter(pagerAdapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
@Override
public boolean onNavigationItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.fr1) {
viewPager.setCurrentItem(0);
} else if (id == R.id.fr2) {
viewPager.setCurrentItem(1);
}else if (id == R.id.fr3) {
viewPager.setCurrentItem(2);
}
else if (id == R.id.Suggestion) {
Intent intent = new Intent(this, Suggestion.class);
startActivity(intent);
}
else if (id == R.id.Logic) {
Intent intent = new Intent(this, logicBehind.class);
startActivity(intent);
}
else if (id == R.id.close) {
finish();
}
drawer.closeDrawer(GravityCompat.START);
return true;
}
@Override
public void onBackPressed() {
boolean wentBack = false;
if (Fragment1.canGoBack()) {
wentBack = true;
Fragment1.goBack();
}
if (Fragment2.canGoBack()) {
wentBack = true;
Fragment2.goBack();
}
if (Fragment3.canGoBack()) {
wentBack = true;
Fragment3.goBack();
}
if (!wentBack) {
new AlertDialog.Builder(this)
.setTitle("Exit app")
.setMessage("Do you want to exit the app?")
.setIcon(R.mipmap.mainlogo)
.setPositiveButton("Yes", (dialog, which) -> super.onBackPressed())
.setNegativeButton("No", (dialog, which) -> {})
.show();
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return super.onCreateOptionsMenu(menu);
}
}
Это то, что я пытался.Код для промежуточной рекламы добавляется в метод onCreate MainActivity.java.