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 6807397
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T19:49:39+00:00 2026-05-26T19:49:39+00:00

I have a problem with an app i’m currently making for Android phones. I

  • 0

I have a problem with an app i’m currently making for Android phones. I have an Activity that has two Buttons. The point is if i press both buttons fast enough (that’s not a good user behaviour), those two buttons fire, while i want just to fire (at very most) only one of them. This a code fragment to example what I mean:

public class ActivityLevels extends Activity {

private boolean launched;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Set the content view of the screen
    setContentView(R.layout.levels);

    //Set lauched flag to false
    launched = false;

    //Initialize buttons
    Button loadLevel01 = (Button) findViewById(R.id.ButtonLoadLevel01);
    Button loadLevel02 = (Button) findViewById(R.id.ButtonLoadLevel02);

    //Set Button Listeners
    loadLevel01.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            launchGame(0);
        }
    });

    loadLevel02.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            launchGame(1);
        }

    });
}

private void launchGame(int level) {

    //Just launch the activity if !lanched
    if(!launched) {
        launched = true;
        //Start Activity
    }
}
}

I’ve been checking the internet for a week or so, and didn’t find any approach to prevent this. As far as i’ve discovered, looks like that someone has already posted a similar issue here: Issue 20073: Button onClick listener can be fired twice even if button is disabled immediately in listener

Btw, i’ve also tryed to disable the button just immediately before the “launchGame(int)” call, but not achieved anything.
This code is just an adapted fragment of the whole activity. I think that’s ok to understand what i mean, but if you need any other description, please let me know.

Thanks in advance, and sorry for any spelling mistakes, my english is not very good at all.

  • 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-26T19:49:40+00:00Added an answer on May 26, 2026 at 7:49 pm

    I actually solved my question. The point was to make my method launchGame(int level) sychronized, so it can’t be accessed more than once before it finishes. This way, let’s say we have two threads from click listeners, because i pressed the button one and button two very very quick: with a synchronized method, it will be called lauchGame(1), finish the action, and then launchGame(2) with the boolean launched flag setted to true.

    This is what i’ve done:

    private void synchronized launchGame(int level) {
    
        //Just launch the activity if !lanched
        if(!launched) {
            launched = true;
            //Start Activity
        }
    }
    

    Anyways, many thanks for all of your answers!

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

Sidebar

Related Questions

I have the following problem: My app has a thread that updates the game
I have problem running my app on Android 2.3 (Gingerbread). The app has a
Hey guys I have a problem with an app I'm making. The thing is
I have some problem with my app. My activity is not a native activity
I have problem with my Android application. I need an application that will send
i have problem with my android app, i searched but cannot find answer, i
I have a problem with an app that uses msmq: on a specific machine
I have a problem with an app that takes an XML feed, parses it,
I have problem in uploading .doc file to .Net WCF from my Android app.
I have a problem with an app that works perfect on my iPhone 4,

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.