Where to set all Listeners?

前端 未结 5 1976
旧巷少年郎
旧巷少年郎 2020-12-18 21:50

Where to set all Listeners for the user interfaces?
Is it good practice to set them in onCreate? This looks so unstructured and strange.
Is

5条回答
  •  时光取名叫无心
    2020-12-18 22:36

    For listeners onCreate() is good place.

    Consider 2 activities A,B.

    A -> B, launching 'B' Activity from 'A', if we come back from B -> A then onStart(), onResume() methods will be called again in 'A' activity and that is redundant. So it's better practice to only add listeners in onCreate() only.

    And, for button listeners you can set attribute android:onClick="method_name" in xml file only.

提交回复
热议问题