getFragmentManager() returns null, with android.support.v4.app.DialogFragment support libraray

こ雲淡風輕ζ 提交于 2019-12-24 07:58:53

问题


here is the fragment dialog:

import android.support.v4.app.DialogFragment;  
public static class SensorMeasurmentsDialogFragment extends DialogFragment {

    public static SensorMeasurmentsDialogFragment newInstance(int title) {

        SensorMeasurmentsDialogFragment frag = new SensorMeasurmentsDialogFragment();
        Bundle args = new Bundle();
        args.putInt("title", title);
        frag.setArguments(args);
        return frag;

        @Override public Dialog onCreateDialog(Bundle savedInstanceState) {
            .....
        }
    }
}

the call to it is done from a regular activity not from a fragmentActivity because my activity already extends mapActivity.

m_measurmentDlg=SensorMeasurmentsDialogFragment.newInstance(R.string.app_name);
m_measurmentDlg.show(m_measurmentDlg.getFragmentManager(),"measurments");

any idea why is it Null?


回答1:


The activity must extend from FragmentActivity for you to be able to use Fragments. You might have to use a workaround at the moment until Google updates their map library.

You might have to use a modified compatibility lib such as this one:

https://github.com/petedoyle/android-support-v4-googlemaps




回答2:


In one of my fragments, I was using replace so when I used add it worked good! might help you




回答3:


I ran into this problem also. The problem happens with setRetainInstance(true) only. My workaround is to use the parent activity's FragmentManager object instead of the DialogFragment's FragmentManager.



来源:https://stackoverflow.com/questions/13213693/getfragmentmanager-returns-null-with-android-support-v4-app-dialogfragment-su

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!