I have a ViewPager with Fragments. When a button is clicked in the Fragment, I launch an Activity on mine. Pressing the back button on my phone when I’m in the Activity, takes me back to my previous screen i.e. the one with the Fragments in the ViewPager.
I’d like to enable the “up” button in my ActionBar and in order to do so, I’ve written the following code:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.detail);
ActionBar actionBar = getActionBar();
actionBar.setDisplayHomeAsUpEnabled(true);
}
Now the “up” button is shown, but clicking it doesn’t take me back to the previous screen. I’d like the “up” button to the same thing as the “back” button.
How can I do this? What am I doing wrong?
Thanks.
You need also to implement what should be done when the up button is clicked: