I'm not sure I understand the question. But I assume you are not very familiar with multi-threading.
The code within Runnable
and the code after the call to runOnUiThread
actually run at the same time, but on different threads. So it is light-years away from nested loops, or from single-threaded nested methods calls.
You can actually make a "blocking" call to another thread to wait for a value, but I don't think it's appropriate to write all of this out in a stackoverflow answer. You should read up on multi-threading and I strongly recommend Java Concurrency in Practice. But you should be warned that it is not a trivial topic that you can pick up in a few days. You can also look at this tutorial; the interface Future
implements the "blocking" call I was referring to.
EDIT
I wrote the above thinking in Java. Things are more complicated with Android since in order to use a Future
, you would need to get an ExecutorService
for the UI thread, and I'm not sure that is possible.
There are many Android specific multi-threading constructs (see for example this tutorial, or the official doc). It is certainly possible to solve your problem, but we don't have enough details. Also, you should probably not try to find a quick fix for your problem, but rethink your whole design so that fits naturally within the Android multi-threading paradigm.