I'm using AlarmManager to wake up the device and run some tasks. These are done inside an IntentService, so on a thread separate from the main one. When the work is done, I'd like to show a toast. However, I'm getting this log warning and no toast is shown:
W/MessageQueue﹕ Handler (android.os.Handler) {b12716d0} sending message to a Handler on a dead thread
java.lang.RuntimeException: Handler (android.os.Handler) {b12716d0} sending message to a Handler on a dead thread
at android.os.MessageQueue.enqueueMessage(MessageQueue.java:320)
at android.os.Handler.enqueueMessage(Handler.java:626)
at android.os.Handler.sendMessageAtTime(Handler.java:595)
at android.os.Handler.sendMessageDelayed(Handler.java:566)
at android.os.Handler.post(Handler.java:326)
at android.widget.Toast$TN.hide(Toast.java:370)
at android.app.ITransientNotification$Stub.onTransact(ITransientNotification.java:55)
at android.os.Binder.execTransact(Binder.java:404)
at dalvik.system.NativeStart.run(Native Method)
I know there are a few other questions on this topic, but I've tried all the suggestions and none worked. I'm using:
Handler handler = new Handler();
handler.post(new Runnable()
{
@Override
public void run()
{
Toast.makeText(context, R.string.toast, Toast.LENGTH_LONG).show();
}
});
I've also tried:
Handler handler = new Handler(Looper.getMainLooper());
I'm still getting the warning and no toast.
What is the way to show this toast from my IntentService?
Thanks in advance!