Posted on Leave a comment

Back button, backstack, back/up navigation, task

Implementing Effective Navigation

Providing up navigation

Providing proper back navigation for deep links, for fragments, for webviews.

Implementing descendant navigation

Task and BackStack

[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]

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.