Android 应用程序 - 每当蓝牙键盘连接/断开连接时触发 onCreate
Android App - Fires onCreate whenever bluetooth keyboard connects / disconnects
我有一个相当简单的 android 应用程序,它使用连接到它的蓝牙条码扫描器。
我遇到的问题是,每当蓝牙扫描仪与 android 设备连接或断开连接时(就像它进入 sleep/wakes 时所做的那样),它会导致 onCreate 方法要调用的活跃 window/layout。
有什么办法可以阻止它吗?
听起来您的 activity 正在重新启动,因为扫描仪的连接(在您的 Android 设备上显示为键盘)被视为配置更改。
我会强烈建议您修改您的应用程序,以便在您的活动重新启动时正确缓存和恢复所有数据 - 就像屏幕旋转时一样。然后连接和断开扫描仪不会影响您的用户。
或者,您可以 tell Android that your app will handle "keyboard" configuration changes and it will not restart your activities when the keyboard connects/disconnects. However, it will still restart your activities for all the other configuration changes that you do not handle - and the list of configuration changes 有点长。
我有一个相当简单的 android 应用程序,它使用连接到它的蓝牙条码扫描器。
我遇到的问题是,每当蓝牙扫描仪与 android 设备连接或断开连接时(就像它进入 sleep/wakes 时所做的那样),它会导致 onCreate 方法要调用的活跃 window/layout。
有什么办法可以阻止它吗?
听起来您的 activity 正在重新启动,因为扫描仪的连接(在您的 Android 设备上显示为键盘)被视为配置更改。
我会强烈建议您修改您的应用程序,以便在您的活动重新启动时正确缓存和恢复所有数据 - 就像屏幕旋转时一样。然后连接和断开扫描仪不会影响您的用户。
或者,您可以 tell Android that your app will handle "keyboard" configuration changes and it will not restart your activities when the keyboard connects/disconnects. However, it will still restart your activities for all the other configuration changes that you do not handle - and the list of configuration changes 有点长。