5

We are facing an issue with Motorola devices running Android 11. On other devices, we are unable to reproduce this issue even on Android 11. We have already looked at UnsupportedOperationException: Tried to obtain display from a Context not associated with one but that thread is not active right now as we are not getting any response.

The issue seems to be linked with opening the keyboard in the TextInput fields. The complete error statement is as follows.

Fatal Exception: java.lang.UnsupportedOperationException

Tried to obtain display from a Context not associated with one. Only visual Contexts (such as Activity or one created with Context#createWindowContext) or ones created with Context#createDisplayContext are associated with displays. Other types of Contexts are typically related to background entities and may return an arbitrary display.
  • Hello, Have you solved this issue or do you have any ideas why it's happening? My app is experiencing the same issue. Thanks – tatocaster Dec 15 '21 at 05:42
  • You can check my answer here https://stackoverflow.com/a/75944952/9133569 – M.Ed Apr 07 '23 at 09:48

2 Answers2

0

Which version of the AppCompat library do you use? If it's 1.2.0 or below and you are using this workaround -> Change Locale not work after migrate to Androidx switch to 1.3.1 or newer and remove the workaround (it's being fixed). Currently, 1.4.1 is the latest

This fixed the exact same problem, exactly on Android 11 and exactly on Motorola for me.

tatocaster
  • 316
  • 3
  • 10
0

As a workaround you can override onKeyUp or onKeyDown (unfortunately I can't see your full stackTrace so I do not know which method you need to override) in the Activity and return true/false in it like this

    override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
        return false
    }
    
    override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
        return false
    }

OneXeor
  • 31
  • 1
  • 3