DialogFragment 的生命周期是什么
What is lifecycle of DialogFragment
我无法通过搜索 Google 找到 android.support.v4.app.DialogFragment
的正确生命周期。我需要这个来实现一些。我们知道 DialogFragment
有一些与 Dialog
.
相同的方法
DialogFragment
扩展了 Fragment
,因此它的生命周期与 Fragment
相同。但是DialogFragment
的其他方法呢?
这里是 Fragment
生命周期。可以提供 DialogFragment
吗?
DialogFragment does various things to keep the fragment's lifecycle
driving it, instead of the Dialog. Note that dialogs are generally
autonomous entities -- they are their own window, receiving their own
input events, and often deciding on their own when to disappear (by
receiving a back key event or the user clicking on a button).
来源:
https://developer.android.com/reference/android/app/DialogFragment#lifecycle
DialogFragment
生命周期类似于fragment:
的生命周期。要测试自己,请将日志放入 dialogFragment
的每个 overrided
方法中,然后 运行 您的代码,您将了解 [=16= 的工作原理].
onAttach
onCreate
onCreateDialog
onCreateView
onActivityCreated
onStart
onResume
就完成或销毁 dialogFragment 而言,生命周期如下:
onPause
onStop
onDestroyView
onDestroy
onDetach
另外我相信这个方法也会帮助你了解 lifecycle
:
@NonNull
@Override
public Lifecycle getLifecycle() {
return super.getLifecycle();
}
奇怪,如果你在onCreateDialog()
中创建了一个AlertDialog
,没有调用onCreateView()
,那么onViewCreated()
也不会调用。
参见 Android DialogFragment onViewCreated not called and 。
我无法通过搜索 Google 找到 android.support.v4.app.DialogFragment
的正确生命周期。我需要这个来实现一些。我们知道 DialogFragment
有一些与 Dialog
.
DialogFragment
扩展了 Fragment
,因此它的生命周期与 Fragment
相同。但是DialogFragment
的其他方法呢?
这里是 Fragment
生命周期。可以提供 DialogFragment
吗?
DialogFragment does various things to keep the fragment's lifecycle driving it, instead of the Dialog. Note that dialogs are generally autonomous entities -- they are their own window, receiving their own input events, and often deciding on their own when to disappear (by receiving a back key event or the user clicking on a button).
来源: https://developer.android.com/reference/android/app/DialogFragment#lifecycle
DialogFragment
生命周期类似于fragment:
的生命周期。要测试自己,请将日志放入 dialogFragment
的每个 overrided
方法中,然后 运行 您的代码,您将了解 [=16= 的工作原理].
onAttach
onCreate
onCreateDialog
onCreateView
onActivityCreated
onStart
onResume
就完成或销毁 dialogFragment 而言,生命周期如下:
onPause
onStop
onDestroyView
onDestroy
onDetach
另外我相信这个方法也会帮助你了解 lifecycle
:
@NonNull
@Override
public Lifecycle getLifecycle() {
return super.getLifecycle();
}
奇怪,如果你在onCreateDialog()
中创建了一个AlertDialog
,没有调用onCreateView()
,那么onViewCreated()
也不会调用。
参见 Android DialogFragment onViewCreated not called and