Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5978875
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:34:47+00:00 2026-05-22T21:34:47+00:00

So I was following along with a 2D graphics tutorial (those interested, its the

  • 0

So I was following along with a 2D graphics tutorial (those interested, its the one @ http://droidnova.com/), and I got to a point where I’ve been experiencing constant crashes in my onTouchEvent() callback. I’m still trying to track the bug, but while trying to debug the issue I noticed that my onTouchEvent callback gets called twice for each event.

For rerference

@Override
    public boolean onTouchEvent(MotionEvent event) 
    {
        int action = event.getAction();
        synchronized (getHolder()) {
            if (action == MotionEvent.ACTION_DOWN) {
                if (gameObjects.size() < 2) {
                    currentlySelected = new GameObject(BitmapFactory.decodeResource(getResources(), R.drawable.icon));
                    currentlySelected.getCoordinates().setX((int) event.getX());
                    currentlySelected.getCoordinates().setY((int) event.getY());
                } else {
                    for (GameObject gameObject: gameObjects) {
                        if (gameObject.inBoundingBox(event.getX(), event.getY())) {
                            currentlySelected = gameObject;
                            break;
                        }
                    }

                    if (currentlySelected != null) {
                        // Remember to remove it from the list so that we don't waste time updating it in updatePhysics twice.
                        gameObjects.remove(currentlySelected);
                    }
                }
            } else if (action == MotionEvent.ACTION_UP && (currentlySelected != null)) {
                gameObjects.add(currentlySelected);
                currentlySelected = null;
            } else if (action == MotionEvent.ACTION_MOVE) {
                currentlySelected.getCoordinates().setX((int) event.getX());
                currentlySelected.getCoordinates().setY((int) event.getY());
            }
        }

No when I put a breakpoint on the first line, and run it in debug mode, when I touch the screen the callback gets called with the following action’s…

  1. action = 0 (MotionEvent.ACTION_DOWN)
  2. action = 0 (MotionEvent.ACTION_DOWN)
  3. action = 1 (MotionEvent.ACTION_MOVE)
  4. action = 1 (MotionEvent.ACTION_MOVE)
  5. action = 2 (MotionEvent.ACTION_UP)
  6. action = 2 (MotionEvent.ACTION_UP)

for each action, the second one gets out at the synchronized call. Anyone know the reason for this behavior?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:34:47+00:00Added an answer on May 22, 2026 at 9:34 pm

    As it turns out, the problem was with the line

    synchronized (getHolder()) {
    

    It should really be

    SurfaceHolder h = getHolder()
    syncronized(h) {
    

    That seemed to solve it for me.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been following along with this excellent asio tutorial , but have got confused
I am following along with tutorials on the site, http://openglbook.com/ , and I have
I am just following along the spring tutorial ( http://static.springsource.org/docs/Spring-MVC-step-by-step/part1.html ) I downloaded this
I'm following along a tutorial (Ruby) that uses a regex to remove all html
I've been toying with the JanRain OpenID PHP Library, mostly following along with a
I'm following along the Rails for Zombies tutorial trying to get the gist of
[for those not following along at home, this is the sequel to Rolling My
I have been following along with the book Practical Django Projects. Very nice book,
I'm fairly new to python and following along with part 4 of the tutorial
So I'm following along with this tutorial , and I'm stuck. In Eclipse, I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.