java.lang.RuntimeException: Handler (android.os.Handler) sending message to a Handler on a dead thread

The problem here is that you are creating a Toast inside a thread that is managed by the IntentService. The system will use the Handler associated with this thread to show and hide the Toast.

First the Toast will be shown correctly, but when the system tries to hide it, after the onHandleIntent method has finished, the error “sending message to a Handler on a dead thread” will be thrown because the thread on which the Toast was created is no longer valid, and the Toast will not disappear.

To avoid this you should show the Toast posting a message to the Main Thread. Here’s an example:

    // create a handler to post messages to the main thread
    Handler mHandler = new Handler(getMainLooper());
    mHandler.post(new Runnable() {
        @Override
        public void run() {
            Toast.makeText(getApplicationContext(), "test", Toast.LENGTH_SHORT).show();
        }
    });

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)