开发者

Android Bluetooth crashes after orientation change

开发者 https://www.devze.com 2022-12-20 01:45 出处:网络
My code is based on the BluetoothChat sample from the API. I connect to another device just fine and I can read and write to the connection no problem. But th开发者_StackOverflow中文版en if I turn the

My code is based on the BluetoothChat sample from the API. I connect to another device just fine and I can read and write to the connection no problem. But th开发者_StackOverflow中文版en if I turn the device the orientation of the UI changes automatically. After this, if I try to write to the Bluetooth connection, my application crashes!

It seems weird that the orientation of the screen somehow affects the Bluetooth. I am new to Android, and I am not yet sure about stuff like when I should be saving and reloading the application's state. Is this one of those times? Does changing the orientation of the screen somehow reset the application's state?!

Thanks!


When the orientation of the screen is changed, your activity is killed and restarted. You must save the state and reinitialize. See here: onSaveInstanceState

0

精彩评论

暂无评论...
验证码 换一张
取 消