自定义DialogFragment onDismiss未调用/工作

时间:2016-05-19 17:31:09

标签: java android dialogfragment

问题是如果我使用FragmentsTransaction,onDismiss不会被触发:

FragmentTransaction transaction = getFragmentManager().beginTransaction();

// For a little polish, specify a transition animation
transaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);

// To make it fullscreen, use the 'content' root view as the container
// for the fragment, which is always the root view for the activity
transaction.add(android.R.id.content, _dialogInfo).addToBackStack(null).commit();

但如果我使用show(),则会调用onDismiss事件:

_dialogInfo.show(getFragmentManager(), DialogFragmentInfo.TAG);

onDismiss在自定义DialogFragment中实现,如下所示:

@Override
public void onDismiss(DialogInterface dialog) {
    super.onDismiss(dialog);
}

我不知道为什么会这样,我在文档中找不到任何解释。

1 个答案:

答案 0 :(得分:0)

来自DialogFragment,文档,生命周期部分:

  

这意味着您应该使用show(FragmentManager,String)或   show(FragmentTransaction,String)添加DialogFragment的实例   到你的UI,因为它们跟踪DialogFragment应该如何删除   当对话被解雇时本身。

据推测,show()做了一些额外的工作来以预期的方式解除对话。