0

I have an logic like this: when enter the edit activity, i will show popup first, then show soft keyboard in the onDismissListener callback, but when i call showKeyboard directly in the callback, the soft keyboard doesn't show. Only i call the view.postRunnable, it will show as expected. As well the activity softkeyboard option is set android:windowSoftInputMode="stateHidden|adjustResize"

private void showKeyboard() {
    InputMethodManager imm = (InputMethodManager)
            getSystemService(Context.INPUT_METHOD_SERVICE);
    imm.showSoftInput(mEditText, InputMethodManager.SHOW_IMPLICIT);
}
dreamtale
  • 2,905
  • 1
  • 26
  • 38

2 Answers2

1

Unless someone with deep knowledge of the inner gears of the UI framework come by to answer, everyone's answer will be a "best guess". So below is my best guess:

That is most likely related to the Window and WindowManager and how they interact with Views and keyboards.

The EditText being passed to the method have a token to your activity window, and here is my guess:

If the window is not in foreground, it can't show a keyboard. So when you post the method call, then that method gets executed after the Window from the Popup is gone, and the Window from the activity is in Foreground.

Budius
  • 39,391
  • 16
  • 102
  • 144
0

The onDismiss() callback is most likely called from non-UI thread, so you can't update your UI directly. That's why you need to post it to the UI thread with view.postRunnable().

Ivan Skoric
  • 1,200
  • 8
  • 18