AndroidKeyboardWatcher icon indicating copy to clipboard operation
AndroidKeyboardWatcher copied to clipboard

Problem when changing orientation

Open dgenest65 opened this issue 8 years ago • 0 comments

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);
    }
}

dgenest65 avatar Aug 17 '17 12:08 dgenest65