I have code like the following to immediately show the soft keyboard when entering my app:
@Override
protected void onResume() {
super.onResume();
...
myEditText.requestFocus();
myEditText.postDelayed(new Runnable() {
@Override
public void run() {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(myEditText, InputMethodManager.SHOW_IMPLICIT);
}
}, 100);
...
}
However, on the Android 2.1 emulator, the keyboard appears and then immediately disappears. If I make the delay longer, like 1000, it reliably appears. On an Android 4.0 emulator, a delay of 100 reliably shows the keyboard, but shorter delays do not.
Does anyone know who might be hiding the keyboard? Is there a reliable way to prevent it? If not, is there a delay I can use to guarantee that the keyboard will show?
If I understand you correctly, I think you can remove the following code in your onResume()
:
myEditText.postDelayed(new Runnable() {
@Override
public void run() {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(myEditText, InputMethodManager.SHOW_IMPLICIT);
}
}, 100);
And simply use android:windowSoftInputMode="stateAlwaysVisible"
for your Activity in the manifest.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With