Skip to content

Attempted to Finish an Input Event ...

March 16th, 2015 - Software(1 min)

… but input event receiver has already been disposed.

This is the error I got while trying to do something off a menu in Android. Silly really. The message is not too revealing so I ended up scouring the net for an answer and scratching my head afterwards…

With a service

My problem was trying to launch a service; I figured it out with a single step:

Disable the filter in Android Studio (logcat). Then, just before this message, I got another one:

03-16 20:51:10.601      468-788/system_process W/ActivityManager﹕ \
Unable to start service Intent { \
    cmp=com.laurivan.android.testapp.dev/com.laurivan.android.testapp.services.MyIntentService \
} U=0: not found

which gave me the real reason: I forgot to add the service to my manifest file. Lesson learned.

With a button

This question refers to the same problem, but in a different scenario: a button’s event displaying a Toast.

My solution involves the same “disable the filter” from above and see the real reason.

To decouple the Toast from an ephemeral widget, I have a solution; write a wrapper:

public class DisplayToast implements Runnable {
    private final Context mContext;
    private final String mText;

    public DisplayToast(Context mContext, String text) {
        this.mContext = mContext;
        mText = text;
    }

    public void run() {
        Toast.makeText(mContext, mText, Toast.LENGTH_SHORT).show();
    }
}

and use it via a Handler object, e.g.:

mhandler = new Handler();
mhandler.postDelayed(new DisplayToast(getApplicationContext(), "Epic message!"), 100 /* ms */);

This way, even if the source goes away, the Toast gets shown.

Share on
Reddit
Linked in
Whatsapp

A little experiment: