When I have a fresh install of my application, NONE of my AyncTasks seem to work. It doesn't matter which it is, they all fail with the message "sending message to a dead thread. "
They're in all sorts of activities doing all sorts of different work, but they all fail.
If I look at the threads in the thread viewer of DDMS, all 5 or so AsynchTask threads appear to be idle and waiting for work.
If I force close the application, and start it back up, they all start working.
They're all started on the UI thread.
Any ideas?
This is due to a bug in AsyncTask in the Android framework. AsyncTask.java has the following code:
private static final InternalHandler sHandler = new InternalHandler();
It expects this to be initialized on the main thread, but that is not guaranteed since it will be initialized on whichever thread happens to cause the class to run its static initializers. In your case, you're probably causing it to be initialized on the worker thread you created.
A simple workaround is to add the following code to the application's onCreate method:
Class.forName("android.os.AsyncTask");
This will force AsyncTask to be initialized in the main thread. I filed a bug on this in the android bug database. See http://code.google.com/p/android/issues/detail?id=20915.
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