views:

123

answers:

1

Hi,

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 then 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!

+1  A: 

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

Segfault
Thanks. This seems like strange behavior to me. I guess it is a simple way to make sure the views redraw in the new orientation, but I think there are better ways they could have gone than reseting the whole thing!
Philipp