I have a pretty weird problem. I'm setting a notification in my Service in order to launch an Activity. When the Activity launches, an AsyncTask
is started. This is how I set up the notification:
CharSequence tickerText = getString(R.string.notificationTextUpdates);
CharSequence contentText = getString(R.string.app_name);
Notification notification = new Notification(icon,
tickerText, System.currentTimeMillis());
Intent notificationIntent = new Intent(
getApplicationContext(), MyActivity.class);
PendingIntent contentIntent = PendingIntent
.getActivity(getBaseContext(), 0,
notificationIntent, 0);
notification.setLatestEventInfo(getApplicationContext(),
tickerText, contentText, contentIntent);
notifManager.notify(0, notification);
If the application is running, everything works, but if it wasn't running before, the AsyncTask's onPostExecute
method doesn't get fired. Instead I get the following exception:
09-30 16:07:52.500: WARN/MessageQueue(27729): java.lang.RuntimeException: Handler{4057ec78} sending message to a Handler on a dead thread 09-30 16:07:52.500: WARN/MessageQueue(27729): at android.os.MessageQueue.enqueueMessage(MessageQueue.java:196) 09-30 16:07:52.500: WARN/MessageQueue(27729): at android.os.Handler.sendMessageAtTime(Handler.java:457) 09-30 16:07:52.500: WARN/MessageQueue(27开发者_StackOverflow中文版729): at android.os.Handler.sendMessageDelayed(Handler.java:430) 09-30 16:07:52.500: WARN/MessageQueue(27729): at android.os.Handler.sendMessage(Handler.java:367) 09-30 16:07:52.500: WARN/MessageQueue(27729): at android.os.Message.sendToTarget(Message.java:350) 09-30 16:07:52.500: WARN/MessageQueue(27729): at android.os.AsyncTask$3.done(AsyncTask.java:214) 09-30 16:07:52.500: WARN/MessageQueue(27729): at java.util.concurrent.FutureTask$Sync.innerSet(FutureTask.java:253) 09-30 16:07:52.500: WARN/MessageQueue(27729): at java.util.concurrent.FutureTask.set(FutureTask.java:113) 09-30 16:07:52.500: WARN/MessageQueue(27729): at java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:311) 09-30 16:07:52.500: WARN/MessageQueue(27729): at java.util.concurrent.FutureTask.run(FutureTask.java:138) 09-30 16:07:52.500: WARN/MessageQueue(27729): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1088) 09-30 16:07:52.500: WARN/MessageQueue(27729): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:581)
Strangely enough, this doesn't happen, when I set up the same notification inside another Activity, so everything works as intended.
I'm quiet confused. My Activity runs in SingleTask mode, I also tried SingleTop mode, which basicly didn't change anything.
See http://code.google.com/p/android/issues/detail?id=20915, which is a possible root cause of the problem. It includes a workaround for the issue.
精彩评论