Android Efficiency - Views
Is it better to findViewById(<resource-id>)
once and store in the scope of your activity (class-wide) or call the above per use, so that the resources are reclaimed when the current scope/method is exited?
I guess it bo开发者_如何学运维ils down to how expensive findViewById()
is compared to how expensive it is to store view objects class-wide.
You're only storing references to views; the storage cost is minimal. Most quality code I've seen finds the view once for each activity, so I take that as best practice. Readability and maintainability are just bonuses.
I think the performance difference is imperceptible. More important than that is how your code looks like... is it readable when you populate your activity class with findViewById
invocations?
精彩评论