@Override public void onBackPressed() { // Do nothing when the back button is pressed }
@Override public void onBackPressed() { Intent intent = new Intent(this, MainActivity.class); startActivity(intent); finish(); }In the example above, the onBackPressed method is overridden to start a new Activity (MainActivity) when the back button is pressed. This can be used, for example, to create a custom back navigation for the application. The android.app package is part of the Android framework and provides a set of core application classes, including the Activity class.