Note that there are some explanatory texts on larger screens.

plurals
  1. PONot all touch events being received by Android view
    text
    copied!<p>In my Android app, I have a custom <code>View</code> that receives touch events. However, it doesn't react every time I touch it - only sometimes. From what I can tell, if I touch the screen, move my finger, and then let go - even if I move only a little - the event is picked up, but if I tap the screen too quickly for my finger to slide across it, nothing happens. How can I fix this?</p> <p>Here is the View's code:</p> <pre><code>public class SpeedShooterGameView extends GameActivity.GameView { public SpeedShooterGameView(Context arg0, AttributeSet arg1) { super(arg0, arg1); } @Override protected GameThread getNewThread(SurfaceHolder holder, Context context) { return new SpeedShooterGameThread(holder, context); } // Program is driven by screen touches public boolean onTouchEvent(MotionEvent event) { SpeedShooterGameThread thread = (SpeedShooterGameThread) getThread(); if (thread.isRunning()) { return thread.recieveTouch(event); } else { return false; } } } </code></pre> <p>I am pretty confident that the object returned in the line <code>SpeedShooterGameThread thread = (SpeedShooterGameThread) getThread();</code> is working as I expect it to, but if the code above looks fine, I'll post the relevant code from that class as well. When <code>thread.recieveTouch(event);</code> is called, the <code>MotionEvent</code> is being sent to another thread.</p> <p>EDIT: I'll go ahead and post the code for <code>SpeedShooterGameThread</code>:</p> <pre><code>public class SpeedShooterGameThread extends GameActivity.GameView.GameThread { //... snip ... private Queue&lt;MotionEvent&gt; touchEventQueue; //... snip ... public synchronized final void newGame() { //called from the constructor, used to go to a known stable state //... snip ... touchEventQueue = new LinkedList&lt;MotionEvent&gt;(); //... snip ... } //...snip... public synchronized boolean recieveTouch(MotionEvent event) { return touchEventQueue.offer(event); } private synchronized void processTouchEvents() { synchronized (touchEventQueue) { while (!touchEventQueue.isEmpty()) { MotionEvent event = touchEventQueue.poll(); if (event == null) { continue; } //... snip .... } } } //... snip ... } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload