Let's say I have a class of this form.
class TestClass implements SomeInterface {
Data myData;
public TestClass() {
}
@Override
public void onData(Data data) {
// do stuff with data
myData = data
}
}
where SomeInterface
does some data processing on a background thread and calls onData
, which runs on a background thread as well. I want to be able to use the data returned in onData
on the Main
thread (updating UI, do other stuff on main thread, etc.) because I know exactly how long after I call the background thread, onData
will be called. Since I'm using SomeInterface
from some library, I can't modify this functionality (I'm not exactly using it as intended).
In Android I would have done something like this but I obviously can't do it in a pure Java application since there's no such thing as a Looper
. Setting an instance variable from a background thread doesn't let me access it from the main thread as well.