Reputation: 1933
I am writing my own InputMethodService
and I want to detect basically when the keyboard pops up and down in order to start and stop doing stuff. I have the simplest `MyInput' class that does very little:
public class MyInput extends InputMethodService {
private static final String TAG = "MyInput";
@Override
public View onCreateInputView() {
Log.d(TAG, "onCreateInputView");
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
return inflater.inflate(R.layout.my_keyboard, null);
}
@Override
public void onStartInput(EditorInfo attribute, boolean restarting) {
super.onStartInput(EditorInfo attribute, boolean restarting);
Log.d(TAG, "onStartInput restarting = " + restarting);
}
@Override
public void onFinishInput() {
super.onFinishInput();
Log.d(TAG, "onFinishInput");
}
}
My view pops up and down normally but in the log, I can see a very strange behavior. Every time the keyboard shows or hide, both functions are called; making it impossible for me to detect when it's actually showing or not.
/** Keyboard not showing, I press an TextView **/
D onFinishInput
D onStartInput restarting = false
/** Keyboard showing, I press back **/
D onFinishInput
D onStartInput restarting = false
/** Keyboard not showing **/
I don't understand why such a simple example doesn't work. Thanks for any help
Upvotes: 4
Views: 4014
Reputation: 6289
The official documentation of the IME Lifecycle is really lacking unfortunately. Through lots of debugging I created (for myself initially) a much better documentation of the IME Lifecycle:
Regarding your initial question, if you want to know if your Keyboard is currently showing or not you shouldn't look at onStartInput
, but you need to look at onStartInputView
. Your Keyboard is visible in the calls between onStartInputView
and onFinishInputView
.
Upvotes: 6