Reputation: 414
I'm looking for some solution to my current problem. I want to execute periodic action like this: 1. Start on 8.00AM 2. Change at 8:45 AM 3. Change at 8:55 AM 4. Change at 9:35 AM etc.
Of course we have to remember, that user can start application at, e.g. 8:33AM. My code looks this:
timer.schedule(new TimerTask() {
@Override
public void run () {
runOnUiThread(new Runnable() {
@Override
public void run() {
//Log.v("Timer: ", String.valueOf(true));
actual.setText("Actual: " + mainScreenNotification.actualy());
}
});
}
}, get8Morning());
private static Date get8Morning(){
Date date = new Date();
date.setHours(8);
date.setMinutes(0);
date.setSeconds(0);
return date;
}
Upvotes: 0
Views: 142
Reputation: 1006554
Use AlarmManager
to set up event triggers like this. Your solution will only work while your application is in the foreground, and it is unlikely that the user will keep your application in the foreground permanently.
Upvotes: 3