Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Back Button to specific activity

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 :)

like image 568
Chad White Avatar asked Aug 23 '13 13:08

Chad White


People also ask

How do I go back to previous activity on android?

Android activities are stored in the activity stack. Going back to a previous activity could mean two things. You opened the new activity from another activity with startActivityForResult. In that case you can just call the finishActivity() function from your code and it'll take you back to the previous activity.

How do I go back to previous fragment from activity?

2 Answers. Show activity on this post. and when you click on back button in the toolbar programmatically go back to the previous fragment using following code. Show activity on this post.


1 Answers

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

@Override
public void onBackPressed()
{
    super.onBackPressed(); 
    startActivity(new Intent(ThisActivity.this, NextActivity.class));
    finish();

}
like image 136
tim.paetz Avatar answered Sep 21 '22 08:09

tim.paetz