Shaggs
Shaggs

Reputation: 73

Android App - Fires onCreate whenever bluetooth keyboard connects / disconnects

I have a fairly simple android app, which uses a bluetooth barcode scanner connected to it.

The problem I'm having, is that whenever the bluetooth scanner connects or disconnects from the android device (as it does when it goes to sleep/wakes up), it causes the onCreate method of the active window/layout to be called.

Is there some way I can stop this?

Upvotes: 4

Views: 1307

Answers (1)

Enrico
Enrico

Reputation: 10675

Sounds like your activity is being restarted, because the connection of the scanner (which appears to your Android device as a keyboard) is considered a configuration change.

I would strongly recommend that you modify your app so that any data is properly cached and restored when your activities are restarted - just like when the screen is rotated. Then connecting and disconnecting the scanner will not impact your users.

Alternatively, you can 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 is kind of long.

Upvotes: 5

Related Questions