Thursday, January 12, 2012

Android app disappears with slide out keyboard

While checking in with a client on our mobile apps they mentioned that on an Android phone with a slide out keyboard the app disappeared every time they slid out the keyboard. I had not tested on any devices with a slide out keyboard so this was news to me.

One of the ladies in support happened to have a slide out phone at home so she brought it into work today. I set it up for debug and plugged it in to my machine to monitor it under Eclipse. No errors in the log, the app just disappeared. I put in break points and found onDestroy was being called but why?

Searching the web and I found you need to add keyboardHidden to your manifest file so the activity will not be destroyed when that event occurs. All my activities looked like this:

android:configChanges="orientation|keyboard"

Now they look like this:


android:configChanges="orientation|keyboard|keyboardHidden"

This solves the issue. I thought keyboard would handle things but you must have both keyboard and keyboardHidden for it to work on all devices.

Of course you only want to do this if you gracefully handle orientation and keyboard changes in your code. All of my activities are very friendly to orientation changes and to the on-screen keyboard appearing or disappearing. The term keyboardHidden does not say to me "the hardware keyboard is sliding out" making it an very unfortunate term on Googles part. A better name might be hardwareKeyboard. I have a feeling the percentage of users with a slide out keyboard is pretty small too but you want to make sure your app works on as many devices as possible. 

I have run our app on my Xoom with a bluetooth keyboard. Even though it operates to the OS like a slide out keyboard in that the on-screen keyboard does not appear it did not have any crash issues. The slide out keyboard must trigger special events. Glad to have it fixed in our code.


3 comments:

  1. Thanks iCaption That - nice to know people are enjoying the blog. I am trying to write to it more often with all the random things that happen to me as I work as a developer.

    ReplyDelete
  2. Dude lose the blue highlighting, it hurts my eyes to read it.

    ReplyDelete
  3. Thanks, this was just what I needed!

    ReplyDelete