My program runs a function upon a button press. Inside, I perform an action and then show a progress dialog spinner. Now I would like to wait until I get a "response", so I acquire a semaphore for T amount of time.
I thought that the function will execute and a progress bar will show up before I try to acquire the semaphore, but instead the program ends up in the semaphore acquire and sleeps, blocking the other functions(probably). The progress dialog shows up AFTER the semaphore times out. How do I ensure that all previous functions completed successfully before proceeding? Here is my onClick function:
public void onButtonClick(View view) throws InterruptedException {
do_action();
progress_dialog.show();
boolean acquired = my_semaphore(15, TimeUnit.SECONDS);
if (!acquired) {
// action timed out
// do something
} else {
// set elsewhere in the program
// a - ok
}
}
How can I implement it in a better way?