How to prevent the activity from loading twice on pressing the button
Add this to your Activity
definition in AndroidManifest.xml
...
android:launchMode = "singleTop"
For example:
<activity
android:name=".MainActivity"
android:theme="@style/AppTheme.NoActionBar"
android:launchMode = "singleTop"/>
In the button's event listener, disable the button and show another activity.
Button b = (Button) view;
b.setEnabled(false);
Intent i = new Intent(this, AnotherActitivty.class);
startActivity(i);
Override onResume()
to re-enable the button.
@Override
protected void onResume() {
super.onResume();
Button button1 = (Button) findViewById(R.id.button1);
button1.setEnabled(true);
}