title: The device BACK key not working and all other key events not responding either
body: <p>The UI of my app is totally built with code. It's an <strong>EMPTY ACTIVITY</strong> with the <strong>activity_main.xml</strong> deleted, and utilizes the following style:</p>
  
  <pre><code>&lt;style name="myTheme" parent="Theme.AppCompat.Light.NoActionBar"&gt;
      &lt;item name="windowNoTitle"&gt;true&lt;/item&gt;
      &lt;item name="windowActionBar"&gt;false&lt;/item&gt;
      &lt;item name="android:windowBackground"&gt;@drawable/splashbg&lt;/item&gt;
  &lt;/style&gt;
  </code></pre>
  
  <p>The basic activity looks like this, with <strong>mainView</strong> <em>(global variable)</em> acting as the root view:</p>
  
  <pre><code>class MyApp: AppCompatActivity(), View.OnTouchListener, OnMapReadyCallback {
  
      override fun onCreate(savedInstanceState: Bundle?) {
          super.onCreate(savedInstanceState)
  
          mainView = FrameLayout(this).apply {
              layoutParams = FrameLayout.LayoutParams(
                  FrameLayout.LayoutParams.MATCH_PARENT,
                  FrameLayout.LayoutParams.MATCH_PARENT
              )
              setBackgroundColor(Color.WHITE)
          }
  
          setContentView(mainView)
          supportActionBar?.hide()
      }
  
      override fun onBackPressed() {
          println("onBackPressed")        
          super.onBackPressed()        
      }
  
      override fun dispatchKeyEvent(event: KeyEvent?): Boolean {
          println("dispatchKeyEvent")
          return super.dispatchKeyEvent(event)
      }
  
      override fun onKeyDown(keyCode: Int, event: KeyEvent?): Boolean {
          println("onKeyDown")
          return super.onKeyDown(keyCode, event)
      }
  
      override fun onKeyUp(keyCode: Int, event: KeyEvent?): Boolean {
          println("onKeyUp")
          return super.onKeyUp(keyCode, event)
      }
  
  }
  </code></pre>
  
  <p>It should also be noted that the app has been migrated to <strong>AndroidX</strong> and is thus utilizing these libraries:</p>
  
  <pre><code>import androidx.appcompat.app.AppCompatActivity
  import androidx.core.app.ActivityCompat
  </code></pre>
  
  <p>The app works as expected except for the key-event methods. I'm trying to intercept the <strong>onBackPressed</strong> event, but nothing seems to be working. None of the events, not <strong>onKeyDown, onKeyUp, onBackPressed,</strong> or <strong>dispatchKeyEvent</strong> are responding. The console does not print any of the <em>println</em> outputs but instead, I get these whenever I press the phone's physical <strong>BACK</strong> key:</p>
  
  <pre><code>2019-11-14 03:57:44.541 16056-16056/? I/GoogleInputMethod: onKeyDown() : keyCode = 4, event = KeyEvent { action=ACTION_DOWN, keyCode=KEYCODE_BACK, scanCode=158, metaState=0, flags=0x48, repeatCount=0, eventTime=280842030, downTime=280842030, deviceId=5, source=0x101 }
  
  2019-11-14 03:57:44.590 1434-1540/? D/BaseMiuiPhoneWindowManager: keyCode:4 down:false eventTime:280842082 downTime:280842030 policyFlags:22000002 deviceId:5 isScreenOn:true keyguardActive:false repeatCount:0
  </code></pre>
  
  <p>Is there some configuration or setting that I might have missed?</p>
  
  <p>TIA.</p>
  
  <hr>
  
  <p><strong>EDIT:</strong> <em>I should also add that this issue occurs when the keyboard is visible. Pressing the <strong>BACK</strong> key dismisses the keyboard but does not trigger the key events.</em></p>