I have two fragments, first is called Summer Jobs Fragment which contains a list of items and the second is called Summer Jobs Details Frgment which contains a the details of each item. Im trying to set back trace so that when I press the back button from Summer Jobs Detail Fragment I go back to Summer Jobs Fragment.
here is my code for the initial transition from SJF to SJDF:
public void onItemClick(
                    AdapterView<?>parent,View view, int position, long id) {
                SummerJobDetailsFragment.mMyAppsBundle.
                        putInt("value", position);
                SummerJobDetailsFragment fragment =
                        new SummerJobDetailsFragment();
                FragmentManager fragmentManager =
                        getFragmentManager();
                list.setVisibility(parent.INVISIBLE);
                fragmentManager.beginTransaction().replace(R.id.displayjobs_detailed, fragment).
                        addToBackStack( "tag" ).commit();
            }
and here is how I modified the OnBackPressed() in the main:
public void onBackPressed() {
        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        if (getFragmentManager().getBackStackEntryCount() > 0 ) {
            getFragmentManager().popBackStack();
        } else {
            super.onBackPressed();
        }
    }
But when I press the back key from SJDF I get a blank screen :
 

fragmentTransaction.addToBackStack() <--dont include this for your first fragment.-->
if(getSupportFragmentManager().getBackStackEntryCount() !=1){
                fragmentTransaction.addToBackStack(null);
            }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With