Code example for Fragment

Methods: getFragmentManager, onActivityCreated

            return v;
        public void onActivityCreated(Bundle savedInstanceState) {
            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();