0

i have a viewpager activity containing fragment named OneFragment.

The Onefragment contains a recyclerview,on items click a fragment called DescriptionFragment opens.

This is how i opened the DescriptionFragment from the Adapter:

 Fragment descriptionFragment = new DescriptionFragment ();
                FragmentTransaction transaction = mContext.beginTransaction();
                transaction.replace(R.id.framelayout, descriptionFragment).addToBackStack(null).commit();

Problem: When i click on backpress button the app finishes.

I want on backpress to close the DescriptionFragment and return back to the OneFragment

Mahdi H
  • 339
  • 8
  • 24

1 Answers1

1

add fragment to stack while comitting a transaction like this

transaction.addToBackStack(OneFragment.getClass().getName);

and your transaction code should look somrething like this

FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction transaction= fragmentManager.beginTransaction();
transaction.replace(..............);
transaction.addToBackStack(null);
transaction.commit(); 
Muhib Pirani
  • 765
  • 1
  • 6
  • 15