0

When I type into the app I am developing, occasionally there will be repeated input characters (that I didn't type) including the "enter" key will be repeated (thus sending my command through an extra one or two times). The input always repeats only once or twice extra, maybe three times extra rarely. It sometimes takes maybe 500-750 milliseconds to repeat, though sometimes it is much faster.

I am making an Android app for my tablet. I have rewritten almost every part of the app now, to try and find what is causing the bug. I have a subclass of EditText that I type into. Originally I was implementing the OnKeyListener interface in the subclass of EditText. I am currently overriding "dispatchKeyEvent" within the Activity itself to handle the key events. I do this so that when the user pressed Enter, for example, it will send the command and then call "selectAll()" of the input to prepare for the user to type another command. I have had the very same bug whether I was implementing the OnKeyListener interface in the customized EditText widget, or overriding "dispatchKeyEvent" in the Activity.

I am working with a bitmap in the app, and the heap is about 90% full after each garbage collection, which happens quite frequently. I don't know if the problem is related to memory - it doesn't seem likely, because the heap would just grow if it needed more space.

When I use the app, I type into a Bluetooth keyboard. Perhaps the Bluetooth drivers could introduce some problems, but the bug rarely if ever happens in other apps (I think I spotted it happen in Chrome only a couple times). It happens on maybe about 1% of keystrokes that go into my app (which is quite frequent because to use this app is to type).

I do get some IInputConnectionWrapper warnings each time I alt-tab out of the app to check LogCat. It says "beginBatchEdit on inactive InputConnection" and also 2 other similar messages. I don't think the warnings are relevant to the problem, but I don't know for sure.

Anyone have a hunch as to what could cause this bug? Or anyone have a good idea of how to isolate the bug and find out where it is coming from? I tried to download some Bluetooth Keyboard "helper" apps, none of which changed anything. I have tried setting 'android:largeHeap="true"' for my application tag in my manifest, which did not cause the heap to be large (using minSdk 8 and targetSdk 11).

2 Answers2

0

You don't have to override dispatchKeyEvent or anything to handle hitting Enter on a EditText. Instead, set the android:imeOptions action correctly (say to actionSend for a 'Send' button on the keyboard), then register your Activity as a OnEditorActionListener, which gets a callback whenever the user clicks the action button or hits enter in the EditText.

ianhanniballake
  • 191,609
  • 30
  • 470
  • 443
  • I do need more control than `android:imeOptions` would give, because I am handling other `KeyEvent`s such as user defined macros. I have gone back to implementing the `OnKeyListener` interface in my `EditText` subclass because that seems more logical, but the input repeat problem persists. – Android Tablet Developer Guy Mar 23 '13 at 14:39
  • Having reworked more of the code now, it seems to me like the problem is within the Bluetooth Keyboard driver... I have noticed it happening when I Alt-Tab (on my Tablet) to switch programs away from my app, and I believe I spotted it happening in Chrome and AIDE (though I've typed into AIDE a lot so far without it hardly ever happening there). Can anyone confirm the Bluetooth Keyboard Driver theory, or suggest a work-around for the drivers to test the theory? Could be my keyboard hardware too I suppose. – Android Tablet Developer Guy Mar 23 '13 at 16:38
0

The problem was the Bluetooth keyboard itself. It was for Mac, not Android. I got a new keyboard, problem solved.