0

I know that when I create a new background thread I can give the new thread a reference to the UI thread's handler so I can send updates to main thread(provided the constructor in the thread class has a handler parameter). For example in the UI it would go like this:

Handler mainHandler;

BackgroundThread myNewThread = new BackgroundThread(mainHandler);
myNewThread.start();

Here's my question:

How can I give the UI thread a reference to a Handler that I create on the background thread, so that I can move data from the UI thread to the background thread???

Yaroslav Mytkalyk
  • 16,950
  • 10
  • 72
  • 99

1 Answers1

0

Handlers are thread safe. You can use them convey messages between threads, it works cross process too (e.g. communication between remote service and UI).

There is one trick tough, doing it right. Here is a good example how to do it right: LINK

Bojan Kseneman
  • 15,488
  • 2
  • 54
  • 59