Android 在键盘插入时崩溃

标签 android exception keyboard

我正在开发一个 Android 应用程序,我需要在其中支持 USB 键盘。我还没有开发出明确支持 USB 键盘的东西,因为我认为每个应用程序都可以使用 USB 键盘。

问题是,当我尝试连接或断开 USB 键盘时,我的应用程序崩溃了,但没有来自应用程序的错误跟踪。

我的设备是安装了 Android 4.1 的 Lenovo。我该怎么做才能解决这个问题?

最佳答案

连接外接键盘时会发生 Activity 配置更改。

要解决崩溃问题,请将以下元素添加到所有 Activity 的 AndroidManifest.xml 中:

android:configChanges="orientation|keyboard|keyboardHidden"

根据 documentation , android:configChanges:

Lists configuration changes that the activity will handle itself. When a configuration change occurs at runtime, the activity is shut down and restarted by default, but declaring a configuration with this attribute will prevent the activity from being restarted. Instead, the activity remains running and its onConfigurationChanged() method is called.

关于Android 在键盘插入时崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18444476/

相关文章:

android - 在 android 上锁定和解锁运行应用程序

python - 为什么 GeneratorExit 和 StopIteration 有不同的基类?

android - Soft KeyBoard 不会在 AlertDialog 的 EditText 中弹出

ios - 操作未完成时如何隐藏(覆盖)所有按钮

java - SCJP - 使用异常处理的重写方法会引发编译器错误

xcode - 变量 + insertText Swift deleteBackward() + insertText (". ")

android - Kotlin - 设置 @Annotations 。函数返回类型?

java - Android WebView 不可滚动

android - 似乎已设置 BLE 通知,但在 Android 上未收到任何通知

java - 我无法让我的方法抛出自定义异常