Search code examples
androidandroid-edittextime

App is freezed with this messge in logcat "Timeout waiting for IME to handle input event after 2500 ms"


I have edit text with value "11491992" sometimes when try to edit it, app is freezed and logcat has this Timeout waiting for IME to handle input event after 2500 ms: com.google.android.inputmethod.latin/com.android.inputmethod.latin.LatinIME

[Update]

I have some EditText views and use RxBinding to control enable/disable submit button based on these EditText views



        val bag = CompositeDisposable()

        RxTextView.textChanges(edFirstName)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .map { it.toString().trim() }
            .subscribe {
                btnSubmit.isEnabled = it.isNotBlank()
                updateRequest.firstName = it
            }.addTo(bag)

        RxTextView.textChanges(edLastName)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .map { it.toString().trim() }
            .subscribe {
                btnSubmit.isEnabled = it.isNotBlank()
                updateRequest.lastName = it
            }.addTo(bag)




Solution

  • This code is OK.

        val bag = CompositeDisposable()
    
        RxTextView.textChanges(edFirstName)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .map { it.toString().trim() }
            .subscribe {
                btnSubmit.isEnabled = it.isNotBlank()
            }.apply { bag.add(this) }
    
        RxTextView.textChanges(edLastName)
            .observeOn(AndroidSchedulers.mainThread())
            .subscribeOn(Schedulers.io())
            .map { it.toString().trim() }
            .subscribe {
                btnSubmit.isEnabled = it.isNotBlank()
            }.apply { bag.add(this) }
    
        }
    

    ANR happens when a long operation is taking place on the main thread. If this thread is busy, Android cannot process any further GUI events in the application, and thus throws up an ANR Application Not Responding dialog.

    From the source code of android.view.inputmethod.InputMethodManager see this function void finishedInputEvent(int seq, boolean handled, boolean timeout) { ... }

    if (timeout) {
        Log.w(TAG, "Timeout waiting for IME to handle input event after "
                + INPUT_METHOD_NOT_RESPONDING_TIMEOUT + " ms: " + p.mInputMethodId);
    } else {
        mH.removeMessages(MSG_TIMEOUT_INPUT_EVENT, p);
    }
    

    Also always try to handle all timeconsuming operations on any thread other than the main thread.

    Update 1:

    see How an app hanged without an ANR?

    • You should use profiler screen.
    • LeakCanary if memory leak.