Question

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).

Was it helpful?

Solution 2

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

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top