I am trying to prevent the activity from loading twice if I press the button twice instantly after the first click.
I have an activity which loads on click of a butt
Let's say @wannik is right but if we have more than 1 button calling same action listener and i click two buttons once almost same time before starting next activity...
So it is good if you have field private boolean mIsClicked = false; and in the listener:
if(!mIsClicked)
{
mIsClicked = true;
Intent i = new Intent(this, AnotherActitivty.class);
startActivity(i);
}
And onResume() we need to return the state:
@Override
protected void onResume() {
super.onResume();
mIsClicked = false;
}
What's the deifference between my and @wannik's answer?
If you set enabled to false in the listener of it's calling view other button using same listener will still be enabled. So to be sure that listener's action is not called twice you need to have something global that disables all callings of the listener(nevermind if it's new instance or no)
What is the difference between my answer and others?
They are thinking in right way but they are not thinking for future return to the same instance of the calling activity :)