Implementing Effective Navigation
Providing proper back navigation for deep links, for fragments, for webviews.
Implementing descendant navigation
[code language=”java”]
// 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();
[/code]
To return to the previous fragment a user should press Back button.
How to programmatically call Back button event:
[code language=”java”]
getFragmentManager().popBackStack();
[/code]
or
[code language=”java”]
super.onBackPressed();
[/code]
To change the back button behaviour:
[code language=”java”]
@Override
public void onBackPressed() {
//Include the code here
return;
}
[/code]
or
[code language=”java”]
@Override
public boolean onKeyDown(int keyCode, KeyEvent event){
if(keyCode==KeyEvent.KEYCODE_BACK)
{
//Include the code here
}
return true;
}
[/code]