mdawdy
Member
In my app I need to call a worker thread which will retrieve technical information from the internet,
update either an EditText or a global variable in the UI thread, and then return to the UI thread where
the updated field will be used in further processing. I have a small experience with Threads having used ASYNCTASK and a simple thread but I am having difficulty getting into this one.
My understanding so far is that, on the one hand "this cannot be done", but on the other hand it can be done by choosing an appropriate synchronization technique. Pretty much all of the examples I have seen do not need the UI to use the returned result, at least not immediately, so I have not recognized an appropriate technique in my searching. I have tried several techniques for passing data between main thread and worker threads.
Examples:
I tried runOnUiThread to set the final value, but It seems to run on the UI thread after the UI thread has carried on?
TextChangedListener in the UI together with runOnUiThread in the worker thread but that does not work either?
I have read about Synchronization but this seems wrong because the main thread must be blocked?
I started looking at WorkManager, RxJava, Eventbus, BroadcastReceiver and more.
It seems to me that what I want to do is quite common and that someone should be able to guide me on which technique might be best to use with perhaps a simple example. I do not mind doing the hard work of learning new stuff but I would really appreciate a starting point for this one.
Thank you, hope you can help
Mick
update either an EditText or a global variable in the UI thread, and then return to the UI thread where
the updated field will be used in further processing. I have a small experience with Threads having used ASYNCTASK and a simple thread but I am having difficulty getting into this one.
My understanding so far is that, on the one hand "this cannot be done", but on the other hand it can be done by choosing an appropriate synchronization technique. Pretty much all of the examples I have seen do not need the UI to use the returned result, at least not immediately, so I have not recognized an appropriate technique in my searching. I have tried several techniques for passing data between main thread and worker threads.
Examples:
I tried runOnUiThread to set the final value, but It seems to run on the UI thread after the UI thread has carried on?
TextChangedListener in the UI together with runOnUiThread in the worker thread but that does not work either?
I have read about Synchronization but this seems wrong because the main thread must be blocked?
I started looking at WorkManager, RxJava, Eventbus, BroadcastReceiver and more.
It seems to me that what I want to do is quite common and that someone should be able to guide me on which technique might be best to use with perhaps a simple example. I do not mind doing the hard work of learning new stuff but I would really appreciate a starting point for this one.
Thank you, hope you can help
Mick