Friday, 15 August 2014

Time in java/android + crashing app -



Time in java/android + crashing app -

ok guys, making android timer app keeps crashing. using chronometer resets when reaches 25 minutes , starts again. beingness done loop in start button onclicklistener. in loop have while loop in assing long type variable value of elapsed time statement

// contents of while loop within loop

while(found==1){ temp = chrono.getbase() + systemclock.elapsedrealtime(); if(temp == 25*60*1000){ found--; }

i multiplied 1000 because time measured in milliseconds? doing wrong or else. thanks.

the while loop blocks main ui thread until status found==1 met. need timer , timertask. or, recommended in this article, can start runnable using handler update chronometer time every 50 or 100 msec. here illustration (not tested , adapted linked article!):

private handler handler = new handler(); handler.postdelayed(runnable, 100); private runnable runnable = new runnable() { @override public void run() { /* need */ boolean istimerready=foobar(); /* , here comes "trick" */ if (!istimerready) handler.postdelayed(this, 100); } };

this starts foobar() every 100 msec. foobar() should homecoming boolean value - calculations in while loop, , update user interface. 1 time foobar() returns true, runnable not restarted.

java android utility

No comments:

Post a Comment