0

I've got separate thread that is running an infinite loop, which also updates the main ui thread via a handler (my thread > handler > ui thread).

Infinite loop on second thread:

while (true) {
  Thread.sleep(100);
  // do xyz
}

However I now would like to modify some objects within the thread VIA the main UI thread.

If I create an additional handler to work in the opposite direction (ui thread > handler > my thread) , I would need to run a looper and my infinite loop at the same time - how do I achieve this? Where do I call the releventlooper.loop()?

Chris Stryczynski
  • 30,145
  • 48
  • 175
  • 286
  • see http://stackoverflow.com/a/25096981/2252830 – pskink Dec 31 '15 at 13:27
  • @pskink I have read through and run the code in the answer you provided. However I still reach the same issue, how do I run the infinite loop on the second thread as well as the looper itself? – Chris Stryczynski Dec 31 '15 at 19:20
  • just use a `HandlerThread` as i have shown in my example, `HandlerThread` is a combination of a `Thread` and a `Looper` – pskink Dec 31 '15 at 19:32
  • from the `HandlerThread` docs: `'''Handy class for starting a new thread that has a looper. The looper can then be used to create handler classes. Note that start() must still be called.'''` – pskink Dec 31 '15 at 19:41

0 Answers0