我想计算当前系统时间和存储时间间隔。我在我的应用程序中使用 admob。当用户点击我要存储当前时间的广告时sharedPreferences,下一个广告应在 10 分钟后显示。
sharedPreferences那么我如何计算存储时间和当前系统时间之间的间隔呢?
这是我的代码。
interstitialAd.setAdListener(new AdListener() {
@Override
public void onAdClosed() {
super.onAdClosed();
startActivity(intent);
interstitialAd.loadAd(new AdRequest.Builder().build());
}
@Override
public void onAdLoaded() {
// Code to be executed when an ad finishes loading.
Toast.makeText(Chapters.this, "loaded", Toast.LENGTH_SHORT).show();
}
@Override
public void onAdFailedToLoad(int errorCode) {
// Code to be executed when an ad request fails.
}
@Override
public void onAdOpened() {
// Code to be executed when the ad is displayed.
}
@Override
public void onAdClicked() {
SimpleDateFormat dateFormat = new SimpleDateFormat("HH:mm:ss");
// Find todays date
String currentDateTime = dateFormat.format(new Date());
sharedPreferences=getSharedPreferences("TimeStamp",MODE_PRIVATE);
SharedPreferences.Editor editor=sharedPreferences.edit();
editor.putString("currenttime",currentDateTime);
editor.commit();
}
@Override
public void onAdLeftApplication() {
// Code to be executed when the user has left the app.
}
}
杨__羊羊
相关分类