Following the advice from https://stackoverflow.com/a/22875621/9023855 why isn't my code working as expected? My plan is to auto-click button.
private boolean threadDone = true;
public void setTimer(final boolean shown_answer, final TextToSpeech tts){
final Handler h =new Handler();
Runnable r = new Runnable() {
public void run() {
if (!tts.isSpeak() && threadDone) {
onTtsFinished(shown_answer);
}
h.postDelayed(this, 1000);
}
};
h.postDelayed(r, 1000);
}
public void onTtsFinished(boolean shown_answer) {
threadDone = false;
if(showAnswer && !shown_answer){
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
button.performClick();
threadDone = true;
}
}, showDelay);
}
if(nextQuestion && shown_answer){
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
button.performClick();
threadDone = true;
}
}, nextDelay);
}
}