I'm having a slight problem with android programming. Basically what i want to achieve is to call REST web service and display results on my (existing) Activity.
Android has certain limitations, so every View on Activity must be edited by the same thread that initially created it.
Every http call MUST be in separate thread. So, since I'm not primarily java developer (QT I did), i did what seamed most logical thing to do.
But when i tried to use that result in my listener method to change Views my application crashed throwing this exception
what i do in listener is this
@Override
public void workDone(WorkerThread thread)
{
int a = (int)thread.getResult();
((ImageView)root.findViewByid(ID).setImageResource(a);
}
Take a look at AsyncTask, it allows you to perform work in a background thread and then return the result to the main thread.
Another alternative is to use Activity.runOnUiThread to call back to the main thread.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With