问题
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