开发者

Android: Interacting with the screen locks out the buttons

I have a both onKeyDown and onMotionEvent overriden in my application. Both of these work, but the onKeyDown has strange behavior. I can always interact with the screen on the device, but after I have interacted with the screen, the buttons do not work. In order to make them work again, I have to push other buttons (ones that I don't use) in order for them to work again. And if I interact with the screen again, the buttons will not work again.

The application I am writing is a game, so the button calls are made to the surface and then passed to the thread running the game.

I am debugging on an HTC Aria, but the problem persists in my emulators as well.

EDIT

The basic code I have is the same as is detailed here.

The code for the buttons are as follows:

    @Override
    public boolean onKeyDown(int keyCode, KeyEvent msg) {
     return thread.doKeyDown(keyCode, msg);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event) {
     return thread.doTouchEvent(event);
    }


    public boolean doKeyDown(int keyCode, KeyEvent msg) {
     synchronized (mSurfaceHol开发者_如何学Goder) {
      if (keyCode == KeyEvent.KEYCODE_MENU) {
       showDialog(DIALOG_PAUSED_ID);
                            return true;
      }
      return false;
     }
    }

    public boolean doTouchEvent(MotionEvent event) {
     synchronized (mSurfaceHolder) {
      if (mState == STATE_PLAYING) {
       if (event.getAction() == MotionEvent.ACTION_DOWN || event.getAction() == MotionEvent.ACTION_MOVE){
              if (event.getX() > 2 * (mWallX / 3)) {

               //shoot arrow
               shoot(event.getX(), event.getY());

               //turn player
               mPlayer.rotate(event.getX(), event.getY());

            return true;
        } else if (event.getAction() != MotionEvent.ACTION_MOVE && event.getX() < 2 * (mWallX / 3)) {
         //temp button on left for stress test
               stressTest = !stressTest;
               return true;
        }
       }
      }
   return false;
     }
    }


Go into Logcat and watch the messages that appear when you recreate your problem.

If you see something like "key dispatching timeout" then the buttons are working, your code is simply busy, blocking any new input from being received.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜