0

i have button in my first activity called Start.

Now when i click on this button it takes 1 to 2 seconds to load the next activity, now at that time the user clicks on the start button multiple times so what happens is that the next activity will open multiple times.

How to overcome this? Is there any way that even if the user clicks on the Start button multiple times open the activity only once.

3 Answers 3

1

Your Options:

  • On click, disable the button and display a ProgressDialog to the user.
  • Use the Intent flag FLAG_ACTIVITY_SINGLE_TOP to ensure only one activity is maintained on the stack. Documentation
  • Use the qualifer launchMode=singleInstance in your AndroidManifest.xml so only one instance of your Activity is allowed at a time. Documentation

I would recommend the first, because it can show the user your application is still working even if it takes a few seconds to do the necessary processing to begin your Activity.

Sign up to request clarification or add additional context in comments.

Comments

1

You can put the launch mode of your 2nd activity as "Single Instance" in your manifest file.

Comments

1

Don't use anything like a launchMode or Intent flags. They are used for different purposes.

Description here

What you have to do is:

  1. Show a progress dialog to clearly show the user that an action(calling 2nd Activity) is in progress. This was user will not try to click the button multiple times
  2. Simply disable the button's click listener after 1st click. This is not recommended because user might not be able to know whether he/she clicked the button. Also this is the case where user tends to click the button multiple times.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.