Reputation: 3846
In my app, I have a home screen with 4 buttons on it. If, for some obscure and unfathomable reason, a user were to click on more than one button at the same time, all of the target activities would open in the order they were clicked.
I have seen a couple of questions on here about something similar, but they don't really answer the question. Hopefully, I don't have to override multitouch methods to handle it.
How can I avoid this behaviour, thus preventing multiple click events at the same time?
Upvotes: 1
Views: 2248
Reputation: 542
I had this exact issue in an application I developed. I found in testing that it was relatively easy to mash the screen with my hand and fire off onClick events for multiple buttons at the same time.
I used the same OnClickListener for all the buttons on the activity. The code was something like this :
protected final android.view.View.OnClickListener m_clickListener = new android.view.View.OnClickListener() {
@Override
public void onClick(View v)
{
if(!m_buttonsEnabled)
{
return;
}
switch(v.getId())
{
case R.layout.button1:
m_buttonsEnabled = false;
final Intent i = new Intent(MainScreenActivity.this, Button1Activity.class);
startActivity(i);
}
break;
case R.layout.button2:
m_buttonsEnabled = false;
final Intent i = new Intent(MainScreenActivity.this, Button2Activity.class);
startActivity(i);
}
break;
}
}
Upvotes: 2
Reputation: 14010
You could set a flag in the original activity and only open a new activity if that flag is set to false--set it to true as soon as you enter an onClick event for one of the buttons.
That being said, do you really foresee this being enough of an issue to warrant such hackiness?
Upvotes: 0