I'm developing an Android application in which I need support a USB keyboard. I haven't developed something to explicitly support the USB keyboard because I thought that every application can use a USB keyboard.
The problem is that when I'm trying to connect or disconnect a USB keyboard, my application crashes without an error trace from the application.
My device is a Lenovo with Android 4.1 installed. What can I do to resolve this problem?
An Activity configuration change occurs when the external keyboard is attached.
To resolve the crash, add the following element to the AndroidManifest.xml
for all activities:
android:configChanges="orientation|keyboard|keyboardHidden"
Per the 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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With