如何在屏幕旋转后显示DialogFragment

时间:2013-09-23 18:40:10

标签: android android-dialogfragment

你能告诉我如何在屏幕旋转后显示DialogFragment吗?我在父级活动中有BroadcastReceiver,当接收者收到某些内容时,我会从showDialog()调用函数GetHelpFragment。在屏幕旋转之前,一切正常,但在轮换后我得到了RuntimeException

public void showDialog() {
   new AutomaticDialogFragment().show(getFragmentManager(), "AutomaticDialogFragment");
}

这就是我在Activity中所拥有的:

@Override
protected void onCreate(Bundle savedInstanceState) {
    mReceiver = new BroadcastReceiver() { 
        @Override 
        public void onReceive(Context context, Intent intent) { 
            String action = intent.getAction(); 
            if (action.equals(GetHelpFragment.INTENT_SHOW_DIALOG)) { 
               getHelpFragment.showDialog();
            }         
        } 
    };

    IntentFilter ifilt = new IntentFilter(GetHelpFragment.INTENT_SHOW_DIALOG); 
    registerReceiver(mReceiver, ifilt);

}

@Override 
public void onDestroy() {
    super.onDestroy();
    unregisterReceiver(mReceiver);
}

为什么它现在有效?我该如何解决?

感谢您的帮助。

0 个答案:

没有答案