handler.post() -> runnable is never executed

757 views
Skip to first unread message

Sobeos

unread,
Aug 5, 2015, 11:19:23 AM8/5/15
to Robolectric
Hi,

my test is indirectly triggering a handler.post(runnable) in one of my application classes.
The runnable is never executed if triggered from the test.
If I replace handler.post(runnable) with runnable.start() everything works as expected.
Does Robolectric (checked with 2.3 and 3.0) have a problem with handlers?
Is there any solution?

Thanks in advane,

    Joe

Michael Grafton

unread,
Aug 5, 2015, 11:52:03 AM8/5/15
to robol...@googlegroups.com

It *should* run immediately upon posting, assuming you are posting it to the UI thread and have not paused the main looper in your test. If these assumptions are correct try to isolate the behavior in a simple environment and post the code.

--
You received this message because you are subscribed to the Google Groups "Robolectric" group.
To unsubscribe from this group and stop receiving emails from it, send an email to robolectric...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sobeos

unread,
Aug 6, 2015, 4:06:31 AM8/6/15
to Robolectric
> assuming you are posting it to the UI thread

It is not posted to the UI thread. The handler is using a HandlerThread().

Christine

unread,
Aug 16, 2015, 4:39:19 PM8/16/15
to Robolectric
I use

ShadowLooper.runUiThreadTasksIncludingDelayedTasks();

to make Runnables run before the test continues.
Reply all
Reply to author
Forward
0 new messages