View losing ability to accept key events

风格不统一 提交于 2019-12-25 02:37:30

问题


I'm a little confused over how key events (back key, volume keys) relate to Views in android.

Take for example the problem I currently have:

Working OK

  • Create Layout (for example, Relative layout)
  • Add View to Layout (A GL SurfaceView)
  • Run app and wait for everything to load (and for GLSurfaceView to be created)
  • Press home key
  • Re-launch app
  • Press back to exit

Not Working OK

  • Create Layout (for example, Relative layout)
  • Add View to Layout
  • Run app and press home key before GLSurfaceView is fully create/displayed
  • Re-launch app quickly again before GLSurfaceView is fully create/displayed
  • Wait for SurfaceView to be displayed
  • Although touch events work Keys no longer work and app can't be exited

why is this? Is there anyway to get focus back to this view? (if 'focus' is the correct terminology in this example).

I've tried

myGLView.requestFocus();

I've also tried various other methods but nothing seems to work - surely there must be a quick and easy way to make sure key events work with the currently visible GLSurfaceView?

来源:https://stackoverflow.com/questions/25021195/view-losing-ability-to-accept-key-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!