Implementing Effective Navigation
Providing proper back navigation for deep links, for fragments, for webviews.
Implementing descendant navigation
// Works with either the framework FragmentManager or the // support package FragmentManager (getSupportFragmentManager). getSupportFragmentManager().beginTransaction() .add(detailFragment, "detail") // this transaction to the back stack .addToBackStack() .commit();
To return to the previous fragment a user should press Back button.
How to programmatically call Back button event:
getFragmentManager().popBackStack();
or
super.onBackPressed();
To change the back button behaviour:
@Override public void onBackPressed() { //Include the code here return; }
or
@Override public boolean onKeyDown(int keyCode, KeyEvent event){ if(keyCode==KeyEvent.KEYCODE_BACK) { //Include the code here } return true; }