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
Other very very simple solution if you no want use onActivityResult()
is disable the button for 2 seconds (or time you want), is not ideal, but can solve partly the problem is some cases and the code is simple:
final Button btn = ...
btn.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
//start activity here...
btn.setEnabled(false); //disable button
//post a message to run in UI Thread after a delay in milliseconds
btn.postDelayed(new Runnable() {
public void run() {
btn.setEnabled(true); //enable button again
}
},1000); //1 second in this case...
}
});