Why the background of the button doesn’t change before the thread starts? It changes after the thread sleep ends. I mention that the background changes if there is no thread.
answer1Top.setBackgroundDrawable(correct);
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//I want to stop this
playerScTop--;
playerScoreTop.setText(String.valueOf(playerScTop));
Create a new class extending
AsyncTask, pass it theViewof which to change the background as well as the two backgroundDrawableinstances, then:onPreExecute()(runs on UI thread), set the first background drawable on your viewdoInBackground()(runs on background thread), sleep 2 secondsonPostExecute()(runs on UI thread), set the other drawable on your viewUntested sample code:
Invoke from your Activity/Fragment/etc like this (no need to keep the created task around in a field):