gpt4 book ai didi

Android 在键盘插入时崩溃

转载 作者:太空狗 更新时间:2023-10-29 16:40:36 24 4
gpt4 key购买 nike

我正在开发一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com