Skip to content Skip to sidebar Skip to footer

Get Fragment From Backstack For Second Time

i'm currently working on browser app for an android. I'm managing new tabs with fragments. So everything is working fine when user open new tab B, and then go back again to tab A.

Solution 1:

Use below function in your Activity,

privatevoidloadFragmentAnimated(Fragment fragment, Bundle args, int containerId, String title)
    {
        fragment.setArguments(args);
        FragmentManagerfragmentManager= getActivity().getSupportFragmentManager();
        FragmentTransactionfragmentTransaction= fragmentManager.beginTransaction();
        fragmentTransaction.replace(containerId, fragment);
        fragmentTransaction.commitAllowingStateLoss();
    }

Then Added Fragment by using ,

loadFragmentAnimated(c, null, R.id.container_name, "title");

And remove fragment by using,

getSupportFragmentManager().beginTransaction().remove(getSupportFragmentManager().findFragmentById(R.id.container_name)).commit();

Post a Comment for "Get Fragment From Backstack For Second Time"