You will have to override onBackPressed() from your activity:
@Override
public void onBackPressed()
{
super.onBackPressed();
startActivity(new Intent(ThisActivity.this, NextActivity.class));
finish();
}
Question
When I click the back button Android goes to the previous activity. Is it possible to set for every activity a custom (back) activity or to set the back button to the home menue of the app?
Help or hints would be great :)
Solution
You will have to override onBackPressed() from your activity:
@Override
public void onBackPressed()
{
super.onBackPressed();
startActivity(new Intent(ThisActivity.this, NextActivity.class));
finish();
}
OTHER TIPS
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
Intent i = new Intent(this.class, yourcustomclass);
startActivity(i);
finish();
}
}
Yes it's possible, just add this method to your activity:
public void onBackPressed() {
//Do the stuff you want on backbutton pressed.
}
Yes you should @override the onBackPressed() function and create an Itent to go wherever you want.
You can override the
@Override
public void onBackPressed(){
}
If you need to go back what ever activity, when click on ActionBar back arrow(Home). overide onSupportNavigateUp()
@Override
public boolean onSupportNavigateUp() {
//onBackPressed(); //this will be go to parent activity
//******************//
// Your intent here //
//******************//
return true;
}