Android - sending message to dead thread handler, Toast error

I use C2DM services, and when I receive the message, I also get the error message "Sending a message to the processor in a dead thread" when a Toast message is displayed, where I want to see the message that arrived. Code Usage:

@Override protected void onMessage(Context context, Intent intent) { Log.e("C2DM", "Message: arived"); Bundle extras = intent.getExtras(); if (extras != null) { //Toast.makeText(this.getApplicationContext(), (CharSequence) extras.get("payload"), Toast.LENGTH_LONG).show(); } } 

onMessage method is used in a class that extends C2DMBaseReceiver . Toast messatge is never displayed.

What is the mistake here? Is there any soul?

Edit:

 09-06 08:59:02.135: WARN/MessageQueue(5654): Handler{44e65658} sending message to a Handler on a dead thread 09-06 08:59:02.135: WARN/MessageQueue(5654): java.lang.RuntimeException: Handler{44e65658} sending message to a Handler on a dead thread 09-06 08:59:02.135: WARN/MessageQueue(5654): at android.os.MessageQueue.enqueueMessage(MessageQueue.java:179) 09-06 08:59:02.135: WARN/MessageQueue(5654): at android.os.Handler.sendMessageAtTime(Handler.java:457) 09-06 08:59:02.135: WARN/MessageQueue(5654): at android.os.Handler.sendMessageDelayed(Handler.java:430) 09-06 08:59:02.135: WARN/MessageQueue(5654): at android.os.Handler.post(Handler.java:248) 09-06 08:59:02.135: WARN/MessageQueue(5654): at android.widget.Toast$TN.hide(Toast.java:344) 09-06 08:59:02.135: WARN/MessageQueue(5654): at android.app.ITransientNotification$Stub.onTransact(ITransientNotification.java:55) 09-06 08:59:02.135: WARN/MessageQueue(5654): at android.os.Binder.execTransact(Binder.java:288) 09-06 08:59:02.135: WARN/MessageQueue(5654): at dalvik.system.NativeStart.run(Native Method) 
+8
android toast android-c2dm
source share
2 answers

There is a workaround. However, I cannot get it to work with this workaround.

I solved a similar problem by creating a handler in the C2DMBaseReceiver constructor and adding Runnable, which shows Toast.

More or less like this:

 public void showToast(String message, Context context){ handler.post(new DisplayToast(message, context)); } private class DisplayToast implements Runnable{ String mText; Context mContext; public DisplayToast(String text, Context context){ mText = text; mContext = context; } public void run(){ Toast.makeText(mContext, mText, Toast.LENGTH_LONG).show(); } } 

And then you can just call the DisplayToast method from a subclass.

Hope it works!

+5
source share

See http://code.google.com/p/android/issues/detail?id=20915 for a possible root cause of the problem. It includes a workaround to solve the problem.

+3
source share

All Articles