Tsabary
Tsabary

Reputation: 3978

What is the lifecycle of a BottomSheetDialogFragment

I am trying to implement Algolia into a BottomSheetDialogFragment and having some issues that I think are relevant to the lifecycle. I a mtrying to figure out what the lifecycle is but i can't find the answers.

I am sorry if there's an obvious why to go around and get that information, but I tried to look at the documentation and couldn't find it.

Specificaly I am eondering about when des onCreateDialog is called, and if there are other unique methods to this fragment. My issue is that my searchBox don't seem to connect well with my Hits View for some reason (the same code worked when I used persistent bottom sheet, but I had to change) and I am wondering if I need to call the searcher and helper somewhere else in my code.

Upvotes: 4

Views: 7973

Answers (2)

Abdul Muqeet
Abdul Muqeet

Reputation: 128

BottomSheet is typically shown as a dialog or a fragment, and its lifecycle is dependent on the lifecycle of the activity or fragment that contains it.

When an activity or fragment containing a BottomSheet is resumed, the onResume() method of the containing activity or fragment is called, but the onResume() method of the BottomSheet itself is not called. I face this issue and don't know why this happened.

Upvotes: 1

Chrisvin Jem
Chrisvin Jem

Reputation: 4070

The lifecycle of BottomSheetDialogFragment is the same as Fragment.

This is quite easy to understand since, BottomSheetDialogFragment extends AppCompatDialogFragment (and adds just onCreateDialog() functions), which in turn extends DialogFragment (and add onCreateDialog() & setupDialog() functions), which in turn extends Fragment.

DialogFragment has the same lifecycle as Fragment (reference). Since, none of the lifecycle methods were touched, AppCompatDialogFragment and BottomSheetDialogFragment will have the same lifecycle as 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 for further reference.

Upvotes: 5

Related Questions