Code example for FragmentManager

Methods: beginTransaction, findFragmentByTag

            FragmentManager fm = getFragmentManager();
            // Check to see if we have retained the worker fragment. 
            mWorkFragment = (RetainedFragment)fm.findFragmentByTag("work");
            // If not retained (or first time running), we need to create it. 
            if (mWorkFragment == null) {
                mWorkFragment = new RetainedFragment();
                // Tell it who it is working with. 
                mWorkFragment.setTargetFragment(this, 0);
                fm.beginTransaction().add(mWorkFragment, "work").commit();
     * This is the Fragment implementation that will be retained across 
     * activity instances.  It represents some ongoing work, here a thread