Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bluetooth keyboard will cause activity destroy and recreate

Bluetooth keyboard will cause activity destroy and recreate if I turn off it or far away from pad(Android) Activity will be recreate how can i avoid this problem

like image 703
Chuang come fromTaiwan Avatar asked Sep 09 '14 00:09

Chuang come fromTaiwan


2 Answers

Pairing a Bluetooth keyboard is considered to be a configuration change: Try adding the below to your AndroidManifest.xml

android:configChanges="keyboard|keyboardHidden"

From: http://developer.android.com/guide/topics/manifest/activity-element.html#config android:configChanges

like image 198
Schleir Avatar answered Oct 02 '22 20:10

Schleir


In contrast to the accepted answer, I found that keyboard|keyboardHidden was not enough. I was working with a Logitech Bluetooth keyboard (model #JNZYR0021).

What did work was this:

<activity
  ...
  android:configChanges="orientation|screenSize|keyboard|keyboardHidden|navigation"
/>

Apparently this Logitech keyboard also changes navigation, which is weird because the Android docs say:

The navigation type (trackball/dpad) has changed. (This should never normally happen.)

Go figure.

like image 20
nlawson Avatar answered Oct 02 '22 21:10

nlawson