Tech Stuff: Prevent Android App from restarting after sliding out the hardware keyboard

CoboltForge Berlin  -  Aug 09, 2012  -  , , , , ,  -  No Comments

One user recently complained about a misbehaviour in our Flashcards App Рevery time he opens his hardware keyboard the app started to show a new question.

This was indeed not intended, but as a matter of design unwanted. By default every time the user slides the keyboard in or out any android app will start a new lifecycle and start over with the onCreate method.

After some research at stackoverflow we figured out one simple, but effective method:

Within the manifest of your application add the the listener for configChanges:

android:configChanges="keyboard|keyboardHidden|orientation"

Now every time the keyboard slides out or in the app will use your own “onConfigurationChanged” method. If there is no such method within your activity, nothing will happen and all keyboard in and out events will be ignored.

Leave a Comment

Your email address will not be published. Required fields are marked *

*