I have run into a problem that may interest many (beginners). Let me show you the code:
startButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
startButton.setVisibility(View.GONE);
if (!started) {
started = true;
timer.start();
information.append("Start 1\n");
tester1.start();
if (cores >= 2) {
information.append("Start 2\n");
tester2.start();
}
if (cores >= 3) {
information.append("Start 3\n");
tester3.start();
}
if (cores >= 4) {
information.append("Start 4\n");
tester4.start();
}
}
}
});
timer, and all testers are threads previously declared.
information is a TextView.
The problem is that when I run the app, the textview changes after the threads finish, even if the threads take 10 seconds to finish. This does happen on the emulator (android 2.3) and on a real (android 4.0) device. The odd thing is, the threads do start at roughly the same time.
You must update any UI components from main thread.
For example