【发布时间】:2019-10-07 23:32:01
【问题描述】:
我正在使用共享首选项来保存用户项目点击,然后在 2 次点击后显示 admob 广告一切正常,但我的问题是当我点击一个项目 2-3 次时,该值被保存到共享首选项但是广告没有显示,我必须退出我的应用程序然后才会显示广告。
我在 google 和 stackoverflow 上搜索过,但没有任何帮助。
附:项目点击启动另一个活动
@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);
}
【问题讨论】:
标签: android android-layout android-intent sharedpreferences