Static member views in activity - Android

后端 未结 4 660
栀梦
栀梦 2020-12-20 05:49

In each of the activities in my application, all the views (grids/lists/buttons... lots of them) are declared as static members of the activity. Is this good practice or is

4条回答
  •  轮回少年
    2020-12-20 06:12

    Personally I'd avoid using static variables as these variables are kept within memory, even though the activity may no longer require them.

    The UI components don't really need to be static as they should be retrieved from the onCreate using the findViewById, or created programatically in the onCreate and there is no need to store the variable permanently.

提交回复
热议问题