For the IO error that is being thrown, I came across:
https://code.google.com/p/android/issues/detail?id=20545
An option is writing a function in onPause() , but a better way would be: (as mentioned by #9 in the same link) - use http://developer.android.com/guide/topics/manifest/activity-element.html#lmode
Also, there is a question to properly close the usb accessory connection, which helps in your case Proper way to close a USB accessory connection