I am developing a simple application using Google Maps V2 API just to get basics and I am facing this error:
09-09 21:21:41.154: E/AndroidRuntime(3796): FAT
Do this in your do in background...
runOnUiThread(new Runnable() {
public void run()
{
if (items.equals("null"))
{
Toast.makeText(getApplicationContext(), "No Event Found",Toast.LENGTH_LONG).show();
}
else {
}
}
});
You cannot execute an AsyncTask
from a background thread. See the "Threading Rules" section of the AsyncTask documentation.
I had a similar issue, problem was that I was having series of Thread from Main Thread. Actually Main UI Thread started a service, which ran on a service and subsequently started another thread, which finally had a FileObserver (another thread), I had to communicate to UI thread by popping a toast message. I tried for several hours, and tried below, it worked as a charm.
//Let this be the code in your n'th level thread from main UI thread
Handler h = new Handler(Looper.getMainLooper());
h.post(new Runnable() {
public void run() {
Toast.makeText(context, "Your message to main thread", Toast.LENGTH_SHORT).show();
}
});
The main key here is the getMainLooper() function of Looper class, which will provide you the Looper against the Main UI thread.