BottomSheetDialogFragment 的生命周期是什么

What is the lifecycle of a BottomSheetDialogFragment

我正在尝试将 Algolia 实现到 BottomSheetDialogFragment 中,但遇到了一些我认为与生命周期相关的问题。我想弄清楚生命周期是什么,但找不到答案。

很抱歉,如果有明显的理由四处寻找该信息,但我试图查看文档但找不到它。

具体来说,我正在考虑何时调用 des onCreateDialog,以及此片段是否还有其他独特的方法。 我的问题是我的 searchBox 似乎由于某种原因不能很好地与我的 Hits View 连接(当我使用 persistent bottom sheet 时,相同的代码有效,但我不得不改变)我想知道我是否需要在我的代码中的其他地方调用搜索器和助手。

BottomSheetDialogFragment 的生命周期与Fragment 相同。

这很容易理解,因为 BottomSheetDialogFragment 扩展了 AppCompatDialogFragment(并仅添加了 onCreateDialog() 函数),后者又扩展了 DialogFragment(并添加了 onCreateDialog() & setupDialog() 函数),它又扩展了 Fragment.

DialogFragmentFragment () 具有相同的生命周期。由于 none 的生命周期方法被触及,AppCompatDialogFragmentBottomSheetDialogFragment 将具有与 Fragment.

相同的生命周期

public Dialog onCreateDialog (Bundle savedInstanceState)

Override to build your own custom Dialog container. This is typically used to show an AlertDialog instead of a generic Dialog; when doing so, Fragment.onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle) does not need to be implemented since the AlertDialog takes care of its own content.

This method will be called after onCreate(android.os.Bundle) and before Fragment.onCreateView(android.view.LayoutInflater, android.view.ViewGroup, android.os.Bundle). The default implementation simply instantiates and returns a Dialog class.

Note: DialogFragment own the Dialog#setOnCancelListener and Dialog#setOnDismissListener callbacks. You must not set them yourself. To find out about these events, override onCancel(android.content.DialogInterface) and onDismiss(android.content.DialogInterface).

Official documentation 供进一步参考。