I have one infinite for loop and i want to run this for loop for 20 seconds after that i want to terminate the loop so what can i do for this?
Here is my code in android:
do {
rl += Character.toString((char) in.read());
// Log.i("RL", "" + rl);
if (rl.contains("<") && checkStream(rl)) {
// Log.i("RL INSIDE", "" + rl);
getNumerAndStatusFromRLString(rl);
rl = "";
}
if (20 SECONDS COMPLETED) {
Log.i("<rl>", "exit");
break;
}
} while (true);
So what can i do to check that 20 seconds is compeleted and now its time to terminate.
Any idea will be appreciated.
I think one of the options may be get time before the loop and while looping check 20 seconds elapsed or not.
Something like below: Not sure about the efficiency.