Я использую общие настройки, чтобы сохранить клики по элементам пользователя, а затем показывать объявления AdMob после 2 кликов, все работает нормально, но моя проблема в том, что когда я нажимаю на элемент 2-3 раза, значение сохраняется в общих настройках.но объявление не показывается, мне нужно выйти из приложения, а затем оно показывается.
Я искал в Google, stackoverflow, но ничего не помогло.
Ps При нажатии элемента запускается другое действие.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
rvWord = findViewById(R.id.recyclerview);
rvWord.setLayoutManager(new LinearLayoutManager(getApplicationContext()));
mDBHelper = new DatabaseHelper(this);
mAdView = findViewById(R.id.adView);
dictionaryAdapter = new DictionaryAdapter(this);
dictionaryAdapter.setCursor(mDBHelper.getDictionaryWord(""));
rvWord.setAdapter(dictionaryAdapter);
mInterstitialAd = new InterstitialAd(this);
mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");
mInterstitialAd.loadAd(new AdRequest.Builder().build());
preferences = getSharedPreferences("click_count",MODE_PRIVATE);
if ( preferences.getInt("count", 0) > 2) {
mInterstitialAd.setAdListener(new AdListener() {
public void onAdLoaded() {
if (mInterstitialAd.isLoaded()) {
mInterstitialAd.show();
}
}
});
editor = preferences.edit();
editor.clear();
editor.apply();
}
// Show Notification Daily
showTimedNotification(this);
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
}