-2

In android Coding I have some doubts.I am working In Paging concepts. I have two Fragments. One is Master Fragment and another one is Transaction Fragment. In master one Button is available. That is vendor. If we click the vendor button we can create a new vendor details. Its work fine to move forward. That is if we click the vendor button the next page is opened. But if return backward by pressing it doesn't work. By pressing the back button from new vendor creation to vendor it works. But if we press back button from vendor to Pager fragment it does n't work. Here I have attached the coding and screen shots. Please help me. Thanks in advance.

Screen Shots


Master Transaction Vendor Vendor Creation The following is the code when we click the backbutton

Fragment fragment = new MainActivity();
                    FragmentManager fragmentManager = getFragmentManager();
                    fragmentManager.beginTransaction()
                            .replace(R.id.frag_act_cont, fragment, "Class Name").commit();
Sreehari
  • 5,621
  • 2
  • 25
  • 59

2 Answers2

0

I don't know if I correctly understand your question. Have a look at the Android Developer Page here

To be able to provide proper back navigation you have to add the fragment to the back stack by

getSupportFragmentManager().beginTransaction()
                       .add(detailFragment, "detail")
                       // Add this transaction to the back stack
                       .addToBackStack()
                       .commit();
luckyhandler
  • 10,651
  • 3
  • 47
  • 64
0

When you press back button the onBackPressed method is called that causes activity to finish.Have a look at this post:http://stackoverflow.com/questions/22011751/life-cycle-of-android-activity-after-pressing-back-button

and try this piece of code.On your backpress method do something like this:

@Override
    public void onBackPressed() {
        super.onBackPressed();
        FragmentManager fragmentManager = getSupportFragmentManager();
        fragmentManager.beginTransaction().replace(R.id.frag_act_cont, "Class Name").commit();
    }
AbhayBohra
  • 2,047
  • 24
  • 36