is it necessary to set Fragment interface listeners to null on detach?

后端 未结 4 1202
感动是毒
感动是毒 2021-01-11 18:50

In Fragment examples involving callbacks, usually they assign the listener in the onAttach method and then set the listener to null in the onDetach method.

Is this l

4条回答
  •  说谎
    说谎 (楼主)
    2021-01-11 19:20

    I never close any of my interface listeners and I use a lof of them, never got any problem.

    The official documentation explaining the communication between fragments does not close the listener in the example either.

    You can also check by yourself in the official sample available here, the listeners are not closed in the fragments. I think Google would have at least mentioned it if it was necessary.

提交回复
热议问题