The UIThread is the main thread of execution for your application.
This is where most of your application code is run. All of your
application components(Activities, Services, ContentProviders,
BroadcastReceivers) are created in this thread, and any system calls
to those applications are performed in this thread.
When you explicitly spawn a new thread to do work in the background,
this code is not is not run on the UIThread. So what happens if the
this background thread needs to do something that changes the UI? This
is what the runOnUiThread
is for. Actually you're supposed to use a
Handler (see the link below for more info on this); it provides these
background threads the ability to execute code that can modify the UI.
They do this by putting the UI-modifying code in a Runnable object and
passing it to the RunOnUiThread method.
(See https://stackoverflow.com/a/3653478/448625 for a more detailed explanation of what UI thread is)
In short, this should fix it:
runOnUiThread(new Runnable() {
public void run() {
// some code that needs to be ran in UI thread
}
});