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

// 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;
    }

 

Leave a Reply

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