We're trying to show a loading screen, do some expensive operations (represented with the sleep) and after the operation finished display a message.
expected behaviour: STEP 1: the visibility of rl_loading (RelativeLayout) is set to visible STEP 2: application sleeps for 2 seconds STEP 3: message is shown
what actually happens: STEP 2: the application sleeps for 2 seconds STEP 1+3: visibility changes and message is shown at the same time
Could anyone please explain why that happens and what to change to achieve the expected behaviour?
mainIcon.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
rl_loading.setVisibility(View.VISIBLE); //STEP 1
try {
Thread.sleep(2000); //STEP 2
} catch (InterruptedException e) {
e.printStackTrace();
}
msg("message"); //STEP 3
}
});