I have a method with a HandlerThread. A value gets changed inside the Thread and I’d like to return it to the test() method. Is there a way to do this?
public void test()
{
Thread uiThread = new HandlerThread("UIHandler"){
public synchronized void run(){
int value;
value = 2; //To be returned to test()
}
};
uiThread.start();
}
Usually you would do it something like this
Then you can create the thread and retrieve the value (given that the value has been set)
tl;dra thread cannot return a value (at least not without a callback mechanism). You should reference a thread like an ordinary class and ask for the value.