androidandroid-handlerpostdelayedandroid-handlerthread

condition signal from handler postDelayed?


I'm very new to Android programming so pls excuse my ignorance...

I'm trying to do simple Android app:

What happens is that buttonClick() is stuck waiting and I'm not even seeing the "---> timeout notify" message after timeout...

What I'm doing wrong ?

EDIT: Tried to fix messed up example...


Solution

  • You can't do what you're trying to do. Handlers run on Looper threads. Handlers that are created with the default constructor will use Looper thread that it is currently running in. In this case, it is the main Looper thread (or UI thread). So, you're locking on the UI Thread and the Handler unlocks on the UI Thread, but it will never reach that point because you're blocking the UI Thread.

    Also, at no point do I see you actually calling the method that posts to the Handler.