Android Core

TIP: Stop Editing

Device only bugs are the worse. You need to go through a device build and reproduce/rinse/repeat. Thankfully these bugs are rare but sometimes they just hit you smack in the face. One such problem occurred when I was debugging a transition on Android related to a login form. I would move between a Form where I had the keyboard open to one where it was closed. This created a nasty effect where the keyboard folded leaving a black space and the transition played out about that black space.

On the simulator this won’t happen, we can’t realistically simulate the virtual keyboard.

It won’t happen on iOS either. Only on Android.

The Android port resizes the display during input and that behavior triggers this end result where the display doesn’t have time to recover before the transition starts.

Initially I thought I can workaround this by invoking:

textField.stopEditing();
callSerially(() -> showOtherForm());

But that only helped on some cases, not all. Even the fact that I used callSerially didn’t help as this depends on a native event going through.

The solution is to use the new stopEditing(Runnable) API. On most OS’s the runnable will be invoked immediately but on Android it will wait for the screen resize before it invokes the code. So this will work as you would expect:

textField.stopEditing(() -> showOtherForm());
Published on Java Code Geeks with permission by Shai Almog, partner at our JCG program. See the original article here: Stop Editing

Opinions expressed by Java Code Geeks contributors are their own.

Shai Almog

Shai is the co-founder of Codename One, he has been programming professionally for over 20 years and developing in Java since 96. Shai worked for countless industry leaders including Sun Microsystems where he was a part of the original WTK (Wireless Toolkit) team & the co-creator of LWUIT. He worked with most major device operators/manufactures including Nokia, Samsung, Sony Ericson, Sprint, Vodafone, Verizon, NTT DoCoMo etc. Shai is a blogger and writer who often speaks at conventions. He is a Java One rockstar and top rated speaker for JavaZone, corporate conventions from Oracle, IBM and many others.
Subscribe
Notify of
guest

This site uses Akismet to reduce spam. Learn how your comment data is processed.

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Back to top button