android.support.v4.app.getFragmentManager() returns null?

From android.support.v4.app.Fragment source:

// The fragment manager we are associated with.  Set as soon as the
// fragment is used in a transaction; cleared after it has been removed
// from all transactions.
FragmentManagerImpl mFragmentManager;

Apparently getFragmentManager() returns support version of fragment manager but only during a transaction (or parent fragment's child fragment manager).

I'm going to use this:

public FragmentManager getHostFragmentManager() {
    FragmentManager fm = getFragmentManager();
    if (fm == null && isAdded()) {
        fm = ((AppCompatActivity)getActivity()).getSupportFragmentManager();
    }
    return fm;
}

Replace this getFragmentManager() with this getSupportFragmentManager() and also make sure that your activity extends FragmentActivity