Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android CountDownLatch.await() freezes UI prematurely

So I am running some threads with a CountDownLatch.

My problem is that when I call latch.await() the UI seems to hang and even UI commands that were called beforehand have no effect. e.g.

btnShare.setVisibility(View.INVISIBLE);
prgSharing.setVisibility(View.VISIBILE);

latch.await()

The first two lines have no effect on the UI.

Any idea why this is and possibly a solution? Thanks.

like image 400
jim Avatar asked Jan 28 '26 01:01

jim


2 Answers

This is most likely because you are blocking the UI-Thread before it can render the Views again. I think you should look at AsyncTask and maybe put your wait logic in the doInBackground() method, or somehow re-think your implementation.

like image 160
Ovidiu Latcu Avatar answered Jan 31 '26 12:01

Ovidiu Latcu


if the UI hangs it is because you call:

latch.await()

on the UI Thread. You have to avoid blocking call on the UI Thread since those are the cause of ANR

like image 23
Blackbelt Avatar answered Jan 31 '26 11:01

Blackbelt