Code example for FragmentManager

Methods: beginTransaction, findFragmentById

0
    @Override 
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        FragmentManager fm = getSupportFragmentManager();
         
        Fragment f = fm.findFragmentById(android.R.id.content);
        if (f == null) {
            FragmentTransaction ft = fm.beginTransaction();
            ft.replace(android.R.id.content, Fragment.instantiate(this, UpdateStatusFragment.class.getName()), sPostFragmentTag);
            ft.commit();
		} 
    } 
     
    private UpdateStatusFragment getPostFragment() { 
    	return (UpdateStatusFragment) getSupportFragmentManager().findFragmentByTag(sPostFragmentTag);
    } 
 
    private ImagePickerFragment getImagePickerFragment() { 
    	return (ImagePickerFragment) getSupportFragmentManager().findFragmentByTag(UpdateStatusFragment.TAG_PICKER); 
    }