Try the Handler class. Build a handler in the Foo constructor. Pass the reference to the Bar class in some way. Call Bar Handler.post ().
To do this, the thread must have a message queue. If this is a purely worker thread, then calling methods directly is not the answer; there is no AFAIR thread interrupt mechanism. To transfer material to a workflow, you need to simulate a message queue for a while - have a Runnnable object queue (to which Bar is added) and check it from time to time.
Ensuring thread safety is a separate big issue. SO is not large enough for everything that has been said and done on this topic.
source
share