0

I need an ad screen(revmob) to show once daily when called from the onCreate method. I grabbed the idea from How do I get an Android application's method to run a method daily with Eclipse? but it is not working since the ad is loading every time the onCreate is called.

The code I have is:

if(runOnceDaily()){
    revmob = RevMob.start(this, REVMOB_APP_ID);
    revmob.showFullscreen(this);
}

private boolean runOnceDaily(){
    boolean result = false;
    SharedPreferences prefs = this.getSharedPreferences(
              "com.blogspot.blog.myapp", Context.MODE_PRIVATE);
    long minStartTime = System.currentTimeMillis() - 1000*60*60*24;
    long lastTimeRan = prefs.getLong("lastTimeRan", -1);
    if (lastTimeRan >= minStartTime) {
        // a day passed.
        //also save the new 'lastTimeRan' in prefs
            result = true;
            prefs.edit().putLong("lastTimeRan", System.currentTimeMillis()).commit();
    }
    return result;
}
4

2 回答 2

0

您可以使用AlarmManager每天运行一个方法

于 2013-08-05T06:02:46.737 回答
0

将 Alarmmanager 与 BroadcastReceiver 类一起使用。在接收器的 OnReceive 方法中调用您需要每天运行的方法。这种方法将非常容易。

于 2013-08-05T06:21:17.353 回答