4

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.

Tsabary
  • 1,688
  • 1
  • 9
  • 30
  • Probably Same as [DialogFragment](https://stackoverflow.com/questions/51614834/what-is-lifecycle-of-dialogfragment). – ADM Jul 08 '19 at 08:00

1 Answers1

3

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.

Chrisvin Jem
  • 3,456
  • 1
  • 5
  • 23
  • 1
    Thank you. So where does onCreateDialog enters? Between which methods? I still don't quite understand where does an experienced programmerg et this information from. Maybe I just don't know how to read the documentaiton properly. – Tsabary Jul 08 '19 at 08:04
  • 1
    Usually a good approach would be to look at the official documentation, source code docs (or maybe use ctrl-f or grep to find occurences quickly), articles, SO questions and images. – Chrisvin Jem Jul 08 '19 at 08:22
  • @Tsabary I've updated my answer, it's usually a good assumption to assume that the child classes will take on the same lifecycle as the parent class. (Ofcourse, best practice would be to confirm that by taking a quick look at the official docs or source code for confirmation before proceeding) – Chrisvin Jem Jul 08 '19 at 08:28