Вопрос

As i understand it, would it not be better to create a fragments event listeners in the fragments onCreate? If it is done in onCreateView it would have to be redone everytime the fragment comes back into view (onResume())? Would it make a difference where it is set?

Это было полезно?

Решение 2

An event is set on a view and hence is restored when the view is restored. For example, lets say we set a listener on a button in a fragment that is created in onCreateView. If at some point of time, if the fragment is restored (without a call to onCreateView), the button is restored along with the listener that is set. The same goes for setting a text/background for a button - you don't have to reset the text/background each time the fragment is resumed.

Другие советы

1) yes it can be better

2) yes you are correct, as event listener is initialised there than the process will be repeated here

enter image description here

3) please have a close look at life-cycle method

4)it always makes difference where you are using and when you are initializing.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top