Call requireBinding() to get the view binding object… or throw an exception if you called it sometime outside of the onCreateView()/ onDestroyView() pair.onDestroyView() simply sets binding to be null. onCreateView() calls that bindingInflater function type to inflate the view binding, holds the value in the binding property, and returns the root View to satisfy the onCreateView() contract. ViewBindingFragment than has its own onCreateView() and onDestroyView() functions. The Java edition of ListFragment has a binding field:įragmentManual/src/main/java/com/commonsware/jetpack/sampler/fragments/ListFragment.kt) The mechanics of this will vary a bit between Java and Kotlin, owing to Kotlin caring deeply about null. The recommended pattern is to set the Java field or Kotlin property that holds the binding object to null in onDestroyView(). In the specific case of view binding, this means that we do not want to hold onto our binding object after onDestroyView() gets called. In between the first onDestroyView() and the second onCreateView(), ideally our fragment has no references to the views that were created and destroyed from the first onCreateView()/ onDestroyView() cycle. Have onCreateView() and onViewCreated() be called again (e.g., the fragment gets re-displayed). Have onCreateView() and onViewCreated() be called.Be created and have onCreate() be called.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |