# Soft keyboard seems to hang app

**URL:** https://discourse.processing.org/t/soft-keyboard-seems-to-hang-app/5165
**Category:** Processing for Android
**Created:** [November 3, 2018, 7:48pm UTC](https://discourse.processing.org/t/soft-keyboard-seems-to-hang-app/5165 "2018-11-03T19:48:15Z")
**Posts on this page:** 13
**Page:** 1

<div class="post-metadata">

### Author: ![dtmr](https://avatars.discourse-cdn.com/v4/letter/d/4da419/32.png) [@dtmr](https://discourse.processing.org/u/dtmr)
#### Post date: [November 3, 2018, 7:48pm UTC](https://discourse.processing.org/t/soft-keyboard-seems-to-hang-app/5165/1 "2018-11-03T19:48:15Z")

</div>

A user has informed me that Android’s soft keyboard and my app hang (probably means stop reacting) when my app opens the soft keyboard. What could be the issue with using the soft keyboard, has anybody ever had problems with it? He has Android 8.1 on a One+ 3. I have tested my app on the emulator with 8.0 and on a tablet with Android 4.2 - no problems.

He sent a screen shot: Keyboard shows up (it is opened in mousePressed() when the user taps a custom text field) and apparently at least one more draw() after mousePressed() is executed because my code starts to render a cursor.

It can’t be the keyboard per se because he has another app from me which uses the soft keyboard, too, and that one works. That one is locked into portrait mode, while the problematic app is landcape. The problematic app sets the “screen always on flag” (\*). There are far more differences but those are two “on the Android side”.

* * *

\*:

```auto
void onCreate(Bundle bundle) 
{
    // override onCreate(): disable sleep mode
  
    super.onCreate(bundle);
    
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
}

```

---

<div class="post-metadata">

### Author: ![kfrajer](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/kfrajer/32/196_2.png) [@kfrajer](https://discourse.processing.org/u/kfrajer)
#### Post date: [November 4, 2018, 1:41am UTC](https://discourse.processing.org/t/soft-keyboard-seems-to-hang-app/5165/2 "2018-11-04T01:41:31Z")

</div>

> [@dtmr](#):
>
> He sent a screen shot: Keyboard shows up (it is opened in mousePressed() when the user taps a custom text field) and apparently at least one more draw() after mousePressed() is executed because my code starts to render a cursor.

It is not exactly clear what the problem is. I would guess both apps use a different version of Android mode. That would be good to document and that would be the first step to check in your journey to find your problem: make sure you are using the same Android mode. You mention the problem is in landscape mode only. Can you confirm you do not have this problem in portrait mode?

Related to the flag **FLAG\_KEEP\_SCREEN\_ON** , I do not think that is a problem. However, if you think it is, remove it as it should not affect your application during this testing.

Kf

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [November 4, 2018, 9:00am UTC](https://discourse.processing.org/t/soft-keyboard-seems-to-hang-app/5165/3 "2018-11-04T09:00:22Z")

</div>

@dtmr===  
It’s difficult to help without seeing the code and knowing how you create and use the editText; - As for the flag, i dont believe that it is the cause, except (battery drain) if the phone is running with low battery level; as for the orientation it does not matter if config changes are really blocked. So, the first thing to know is the kind of error message this user got: is it a crash or is it an ANR??? - Other one would be to know at what point this happens: was the phone rotated or not??? Does it happens at the very beginning?? - Does it happens each time???: well, a screenshot tells nothing about these questions!

---

<div class="post-metadata">

### Author: ![dtmr](https://avatars.discourse-cdn.com/v4/letter/d/4da419/32.png) [@dtmr](https://discourse.processing.org/u/dtmr)
#### Post date: [November 4, 2018, 12:03pm UTC](https://discourse.processing.org/t/soft-keyboard-seems-to-hang-app/5165/4 "2018-11-04T12:03:56Z")

</div>

> the kind of error message this user got: is it a crash or is it an ANR???

No error message. The user told me that my app and the keyboard just stop taking input. At that moment, the app looks perfectly normal. The app is there, the keyboard is there:

 ![screenshot](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/7/7d816f7b71eba00a13eb39f48dea704929a77a96.png)

> how you create and use the editText

I don’t think that matters because the edit code runs on my Windows, my Linux, my Mac OS X, my Android tablet and the Android emultator. It’s very simple anyway: Listen to keystrokes (keyPressed()), append 0…9 and “.” to a string, which is displayed. Backspace is implemented, too. Nothing else. No GUI library, no text marking, no cursor movements. Just used to enter a number.

IMHO it must be something on the Android side. Is there a way to install the 8.1.1 emulator for use with Processing without installing the entire Android Studio?

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [November 4, 2018, 2:28pm UTC](https://discourse.processing.org/t/soft-keyboard-seems-to-hang-app/5165/5 "2018-11-04T14:28:38Z")

</div>

@dtmr====  
looks like an ANR , which happens (depending of the phone) often, because your app is doing too much on the main ui thread: i see that the input is an IP and i suppose that you try to connect to this IP: if that is done on the main ui thread ANR is possible, or if you try to modify the GUI while the user is typing its input or…Any case, in order to be sure a) try to ask to this user if after the freeze he has got some message (ANR are very typical but not send immediately, it takes 5 seconds to appear) and if yes try to create a runnable…  
more details here: [https://developer.android.com/training/articles/perf-anr](https://developer.android.com/training/articles/perf-anr)

---

<div class="post-metadata">

### Author: ![dtmr](https://avatars.discourse-cdn.com/v4/letter/d/4da419/32.png) [@dtmr](https://discourse.processing.org/u/dtmr)
#### Post date: [November 5, 2018, 8:13am UTC](https://discourse.processing.org/t/soft-keyboard-seems-to-hang-app/5165/6 "2018-11-05T08:13:18Z")

</div>

The user has provided more information:

- He doesn’t really have Android. He has two Lineageos devices (equivalent to 8.1). My app hangs on all of them after opening the keyboard. Lots of memory, Full HD, AOSP standard keyboard.

- No error messages

- Removing FLAG\_KEEP\_SCREEN\_ON makes no difference.

> input is an IP and i suppose that you try to connect to this IP

The app connects to the IP but only after the IP has been entered. Networking or blocking can’t be the issue when the keyboard is opened.

- He says there is no visual feedback from the keyboard if keys are tapped or if the device is rotated and it is not possible to switch to another layer (from a-z to numbers)

- It seems to affect not only the app but the system in the following way: If the extended start menu is opened (“shutdown restart screenshot”), this menu is non-responsive:

 ![screenshot](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/6/6afdff303afcb2255eec2bc6ddd1cd4e043a07ce.jpeg)

- If the user bypasses the keyboard (clicking ok and accepting IP from configuration file), the app starts normally, the network connection works and everyhing else works. It is a complex app. With one exception: There is a toolbar button in the app that opens the soft keyboard. That hangs, too.

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [November 5, 2018, 2:03pm UTC](https://discourse.processing.org/t/soft-keyboard-seems-to-hang-app/5165/7 "2018-11-05T14:03:48Z")

</div>

@dtmr ====  
looking at your last post and what says the user i think that there could be some specific problem with its OS: there is not any ANR message (but is it implemented by this 0S, i dont know) and yes it seems to be an OS crash…without crash! = in this case i cannot help; what i cannot understand is why the keyboard does not hang at the very beginning and works till (looking to the IP) last char…

---

<div class="post-metadata">

### Author: ![dtmr](https://avatars.discourse-cdn.com/v4/letter/d/4da419/32.png) [@dtmr](https://discourse.processing.org/u/dtmr)
#### Post date: [November 5, 2018, 2:23pm UTC](https://discourse.processing.org/t/soft-keyboard-seems-to-hang-app/5165/8 "2018-11-05T14:23:26Z")

</div>

> cannot understand is why the keyboard does not hang at the very beginning and works till (looking to the IP) last char…

It hangs at the beginning - the displayed IP is a default, not user input.

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [November 5, 2018, 6:39pm UTC](https://discourse.processing.org/t/soft-keyboard-seems-to-hang-app/5165/9 "2018-11-05T18:39:30Z")

</div>

@dtmr===

ah! - ok: that 's more logical! - Anyway i persist to think to something ANR like and in this case i would try to put the whole editext stuff inside a runnable…

---

<div class="post-metadata">

### Author: ![dtmr](https://avatars.discourse-cdn.com/v4/letter/d/4da419/32.png) [@dtmr](https://discourse.processing.org/u/dtmr)
#### Post date: [November 6, 2018, 8:58am UTC](https://discourse.processing.org/t/soft-keyboard-seems-to-hang-app/5165/10 "2018-11-06T08:58:28Z")

</div>

In the meantime, the user has found out that the hanging keyboard is related to "the display size (dpi)" setting of his device:

The keyboard apparently works with the second-smallest setting.

At that point, everything on the smartphone is too small to be read without glasses. There is nothing special about the resolution of this device. Full HD.

---

<div class="post-metadata">

### Author: ![akenaton](https://avatars.discourse-cdn.com/v4/letter/a/a88e4f/32.png) [@akenaton](https://discourse.processing.org/u/akenaton)
#### Post date: [November 6, 2018, 12:12pm UTC](https://discourse.processing.org/t/soft-keyboard-seems-to-hang-app/5165/11 "2018-11-06T12:12:46Z")

</div>

@dtmr=== so the inquiry is going on…By curiosity i would know what is exactly this “smallest setting” value…

---

<div class="post-metadata">

### Author: ![dtmr](https://avatars.discourse-cdn.com/v4/letter/d/4da419/32.png) [@dtmr](https://discourse.processing.org/u/dtmr)
#### Post date: [November 7, 2018, 6:19pm UTC](https://discourse.processing.org/t/soft-keyboard-seems-to-hang-app/5165/12 "2018-11-07T18:19:22Z")

</div>

According to the user with that problem, around 400 dpi: 384 dpi works, 432 and 480 dpi not.

 ![Screenshot_20181106-155511_Dev_Tools](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/a/a1ce2774e543381d64b7d900a80be99dc4255914.png) ![Screenshot_20181106-155429_Dev_Tools](https://canada1.discourse-cdn.com/flex036/uploads/processingfoundation1/original/2X/b/bd7861d73e2cb07bcd6df749fdcf7c4d003f5109.png)

---

<div class="post-metadata">

### Author: ![dtmr](https://avatars.discourse-cdn.com/v4/letter/d/4da419/32.png) [@dtmr](https://discourse.processing.org/u/dtmr)
#### Post date: [November 13, 2018, 4:02pm UTC](https://discourse.processing.org/t/soft-keyboard-seems-to-hang-app/5165/13 "2018-11-13T16:02:26Z")

</div>

Update: Couldn’t solve this problem. Wrote my own soft keyboard.
