java - Check time every 5 minutes and compare it to button's time - Android -
i have class called eventbutton extends button.
all of button's settings in class, onclick() etc.
i have home activity has scrollview
the eventbuttons added home activity's scroll view when user presses menu button. don't instantiate object call new eventbutton()
when user clicks on button dialog displayed , user set's name of "event" , time of "event".
the name , time displayed on button inside scollview on home activity.
my question is, how go refreshing eventbutton every, say, 5 minutes check if time set on has passed. have tried timertask , timer , handler neither seem work. timertask kept crashing, found out it's better use handler in android.
private void scheduledelay() { eventbutton.this.postdelayed(new runnable() { @override public void run() { // todo auto-generated method stub int mhour = calendar.get(calendar.hour_of_day); int mminute = calendar.get(calendar.minute); if(eventbutton.hour < mhour || eventbutton.minute < mminute) { eventbutton.this.setbackgroundcolor(color.red); } eventbutton.this.postdelayed(this, 5); } }, 5); }
the above called when user sets name , time of eventbutton in alertdialog.
update
the problem doesn't seem handler after all. seems when try hour , minute it's crashing.
change usage 5 minutes (5 * 60 * 1000) not 5 milliseconds:
private void scheduledelay() { eventbutton.this.postdelayed(new runnable() { @override public void run() { // todo auto-generated method stub int mhour = calendar.get(calendar.hour_of_day); int mminute = calendar.get(calendar.minute); if(eventbutton.hour < mhour || eventbutton.minute < mminute) { eventbutton.this.setbackgroundcolor(color.red); } else { // wait 5 minutes scheduledelay(); } } }, 300000); }
Comments
Post a Comment