Code example for Fragment

Methods: isDetached

0
 
            // Check to see if we already have a fragment for this tab, probably 
            // from a previously saved state.  If so, deactivate it, because our 
            // initial state is that a tab isn't shown. 
            mFragment = mActivity.getFragmentManager().findFragmentByTag(mTag);
            if (mFragment != null && !mFragment.isDetached()) {
                FragmentTransaction ft = mActivity.getFragmentManager().beginTransaction();
                ft.detach(mFragment);
                ft.commit();
            } 
        } 
 
        public void onTabSelected(Tab tab, FragmentTransaction ft) {
            if (mFragment == null) {
                mFragment = Fragment.instantiate(mActivity, mClass.getName(), mArgs);
                ft.add(android.R.id.content, mFragment, mTag);
            } else { 
                ft.attach(mFragment);
            } 
        }