Hi,
I’ve just started going through your great book, and on the GeoQuiz app, I am trying to add in a little functionality so that the question changes automatically a little after the toast finishes. I’m trying to use the following code:
private void checkAnswer(boolean userPressedTrue){
int messageResID = (userPressedTrue==mQuestionBank[mCurrentIndex].isTrueQuestion()) ? R.string.correct_toast : R.string.incorrect_toast;
Toast toast =Toast.makeText(QuizActivity.this,messageResID,Toast.LENGTH_SHORT);
Thread thread=new Thread(){
@Override
public void run(){
try{
sleep(3000);
QuizActivity.this.nextButton_click();
}catch(Exception e){}
}
};
toast.show();
thread.start();
}
but I get weird results, either the question changes immediately, as though Thread.sleep returns straight away without sleeping, or the question doesn’t change at all but the app continues to respond, as though Thread.sleep threw an exception.
Unfortunately I haven’t read the debug chapter yet, so can’t debug it !
Does android do weird things with threads ?
Cheers,
Stuart