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

  • SEARCH
  • Home
  • 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 7033649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T01:05:29+00:00 2026-05-28T01:05:29+00:00

My app needs to check whether user double clicks or not. But I can’t

  • 0

My app needs to check whether user double clicks or not. But I can’t use Android OnDoubleClickListener or something likes that. Just implements it :

My problem is diferent from “normal” double click.

What I want is:
If user double clicks, run the Y activity.
If user clicks 1 click only, wait 500 ms then run the X activity.
If user click 2 click slowly, run the X activity

This is my code:

        long now = System.currentTimeMillis();
        thisTime = now;

        if (thisTime - lastTouchTime < WAIT_TIME) {
            // Double tap

            this.getContext()
                    .getApplicationContext()
                    .startActivity(
                            (new Intent(getContext(),
                                    ChangePlaceActivity.class))
                                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));

            // If is double tap, reset to start state.
            lastTouchTime = -1;
            return true;
        } else {
            // Too slow or first click
            // If not double tap, save last state for next check

            lastTouchTime = thisTime;

            Log.d("Worker thread", "Declare" + System.currentTimeMillis());
            Thread t = new Thread() {
                public void run()
                {
                    try {
                        sleep(WAIT_TIME);
                    } catch (InterruptedException e) {
                        // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                }
            };
            t.start();
            try {
                t.join();
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            Log.d("Worker thread", "" + System.currentTimeMillis());

            // start MainAct
            Log.d("Single Click", "Yes");
            this.getContext()
                    .getApplicationContext()
                    .startActivity(
                            (new Intent(getContext(),

                            MainActivity.class))
                                    .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK));
        }

If use code like this, I can’t got double click. If remove thread.run() thread.join(). It will start MainActivity before ChangePlacecActivity.

Is there any solution for this problems?
Thank you in advance!

Sorry for my bad English.

  • 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-28T01:05:29+00:00Added an answer on May 28, 2026 at 1:05 am

    You can use a Handler for this. Something like:

    (class-level declarations)

    Handler handler = new Handler();
    Runnable singleClickTask = new Runnable() {
      public void run() {
        //run X activity
        firstClick = true;
      }
    };
    boolean firstClick = true;
    

    (and then in onClick)

    if (firstClick) {
      handler.postDelayed(singleClickTask, 500);
      firstClick=false;
    } else {
      handler.removeCallbacks(singleClickTask);
      firstClick=true;
      //run Y activity
    }
    

    Please debug this yourself before using it blindly, but I think it’s right.

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

Sidebar

Related Questions

Is it possible to check on startup of an Android app whether the user
Is it possible to check on startup of an Android app whether the user
I am developing an application in cocoa,which needs to check whether that app is
In Android, I have some code to check whether the user has GPS switched
I have an app that needs to check a database table every minute. The
So I have a small C# app that needs to periodically check the contents
My current app needs to store address information for a user. I'm currently debating
My Cocoa app needs some small dynamically generated windows. How can I programmatically create
Our web app needs to be made PCI compliant, i.e. it must not store
I have done some research on how to check whether a user is within

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.