Android Back button for specific activity

When I click the back button, Android goes to the previous action. Is it possible to set up a regular (reverse) activity for each type of activity or set the "Back" button on the applicationโ€™s home mode?

Help or tips would be great :)

+6
source share
6 answers

You will have to override onBackPressed () from your activity:

@Override public void onBackPressed() { super.onBackPressed(); startActivity(new Intent(ThisActivity.this, NextActivity.class)); finish(); } 
+18
source
 public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_BACK) { Intent i = new Intent(this.class, yourcustomclass); startActivity(i); finish(); } } 
+3
source

Yes, maybe just add this method to your activity:

 public void onBackPressed() { //Do the stuff you want on backbutton pressed. } 
+2
source

Yes, you should @ override the onBackPressed () function and create an Itent to go where you want.

+1
source

You can override

 @Override public void onBackPressed(){ } 
+1
source

If you need to go back when you press the ActionBar back arrow (Home). overide onSupportNavigateUp ()

 @Override public boolean onSupportNavigateUp() { //onBackPressed(); //this will be go to parent activity //******************// // Your intent here // //******************// return true; } 
+1
source

Source: https://habr.com/ru/post/952361/


All Articles