- #1
Darkmisc
- 220
- 31
- TL;DR Summary
- I have a runnable that works fine when it's the only thread that I run. However, the timing of its steps suffers when I run multiple threads on handler.
Hi everyone
I'm making a Whack-a-mole-style game for learning katakana. I have a textView for the question, a textView for the answer and nine buttons.
I have a SetQuestion runnable to show the question and answer. Each button has its own runnable that controls how long the button flashes, what text it displays and how many button presses are required. Another runnable called "Button Chooser" determines which buttons flash.
The SetQuestion runnable works fine when it is the only thread in handler. However, the questions and answers stop matching when I run SetQuestion with Button Chooser.
I've tried running SetQuestion and Button Chooser and separate handlers and it doesn't fix the problem.
This is the code for SetQuestion
public Runnable SetQuestion = new Runnable() {
textView29 has the question and hintView the answer. It seems running multiple threads is causing enough lag so that the questions and answers get out of synch. Is there a way to fix this?Thanks
I'm making a Whack-a-mole-style game for learning katakana. I have a textView for the question, a textView for the answer and nine buttons.
I have a SetQuestion runnable to show the question and answer. Each button has its own runnable that controls how long the button flashes, what text it displays and how many button presses are required. Another runnable called "Button Chooser" determines which buttons flash.
The SetQuestion runnable works fine when it is the only thread in handler. However, the questions and answers stop matching when I run SetQuestion with Button Chooser.
I've tried running SetQuestion and Button Chooser and separate handlers and it doesn't fix the problem.
This is the code for SetQuestion
public Runnable SetQuestion = new Runnable() {
SetQuestion:
public Runnable SetQuestion = new Runnable() {
public void run() {
Qtimer++;
if (Qtimer%10==1){
pickFromArray = ThreadLocalRandom.current().nextInt(0, arraySize);
// whichSound();
textView29.setText(listromT.get(pickFromArray));
hintView.setText(listT.get(pickFromArray));
}
if (Qtimer%10==6){
// whichSound();
pickFromArray2 = ThreadLocalRandom.current().nextInt(0, arraySize);
textView29.setText(listromT.get(pickFromArray));
hintView.setText(listT.get(pickFromArray));
}
if (Qtimer>199){
Qtimer=110;
}
handler2.postDelayed(this, 1000);
}
};
textView29 has the question and hintView the answer. It seems running multiple threads is causing enough lag so that the questions and answers get out of synch. Is there a way to fix this?Thanks