Showing posts from April, 2014

CalledFromWrongThreadException in Android

I got CalledFromWrongThreadException when I tried to update UI from another thread. I have two threads in my app, one our main UI thread and another for network operations. So when I tried to update UI from "network thread", I got the exception CalledFromWrongThreadException.

Solution: The solution for this is update the UI in UI thread. For this, just put the update UI statements inside runOnUiThread block. First get the activity context, and call runOnUiThread(). Like,
runOnUIThread(new Runnable() { public void run() { ... } });
Happy Coding