AndroidKeyboardWatcher
AndroidKeyboardWatcher copied to clipboard
Problem when changing orientation
This problem happen when activity attribut: android:configChanges="orientation" is used in the manifest. With this attribute set, the activity is not destroyed/recreated when we change orientation. That mean that KeyboardWatcher is not destroyed/recreated neither. So the initialValue is now wrong and since the detection of the presence of the keyboard is base on that, onKeyboardClosed() and onKeyboardShown() are thrown wrongly. So it would be nice to add support for that use case, for example add a resetInitialValue method or something like that.
For now the solution I found is to destroy/recreate the KeyboardWatcher in the onConfigurationChanged method:
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if (mKeyboardWatcher != null) {
mKeyboardWatcher.destroy();
mKeyboardWatcher = new KeyboardWatcher(this);
mKeyboardWatcher.setListener(this);
}
}