I am developing an Android app. I am using ActionBar with AppCompactActivity. In my app, I add back button to action bar. But when I click on it, it is not going back to the previous activity. For example, I start activity 2 from activity 1. Activity 2 contains action bar with back button. But when I click on action bar back button of activity 2, it is not going back to activity 1.
This is how I set action bar for activity 2:
public class EditProfileActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.edit_profile);
Toolbar toolbar = (Toolbar)findViewById(R.id.profile_action_toolbar);
setSupportActionBar(toolbar);
setTitle("Edit Profile");
ActionBar actionBar= getSupportActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
}
This is how I started activity 2 from activity 1:
Intent i = new Intent(MainActivity.this,SecondActivity.class);
startActivity(i);
It is not going back when I click this button
Why it is not going back?