Last active
September 30, 2016 22:48
-
-
Save TheSalarKhan/b3595ea44320b80b5ce2f7daafc0121c to your computer and use it in GitHub Desktop.
How to stop main activity from exiting on pressing theback button
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package foo.foo.foo.foo; | |
import android.content.Intent; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
public class MainActivity extends AppCompatActivity { | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
} | |
/** | |
This override here is what makes this android activity goto home, upon pressing the back button. | |
*/ | |
@Override | |
public void onBackPressed() { | |
Intent intent = new Intent(Intent.ACTION_MAIN); | |
intent.addCategory(Intent.CATEGORY_HOME); | |
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); | |
startActivity(intent); | |
} | |
public void onClickTransaction(View view) { | |
startActivity(new Intent(MainActivity.this,SwipeCard.class)); | |
} | |
public void onClickSalesReport(View view) { | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment