开发者

Should I use many simple listeners or one complex one?

开发者 https://www.devze.com 2023-03-18 23:54 出处:网络
I\'m new to developing in Android although I have much experience with Java and .Net (but I\'ve been on a hiatus for a bunch of years开发者_如何学JAVA). This is my first time programming for mobile pl

I'm new to developing in Android although I have much experience with Java and .Net (but I've been on a hiatus for a bunch of years开发者_如何学JAVA). This is my first time programming for mobile platforms and I have been thinking that with the limited memory of these devices my usual approach to event-handling may not work here.

Usually, I prefer to have a dedicated listener / event-handler for each control, let's say, a bunch of buttons. I think it is easier to maintain the code and it feels more Object-Oriented-like, so to say.

But in Java, each listener is a new instance of a class, so if I have 20 buttons and 20 listeners, I think I'm going to spend more memory than necessary. Is this true?

What are the pros and cons of using one listener for all these buttons? What is the recommended practice?

Thanks.


Don't get headache about 20 Listeners. The memory footprint is neglectable. Try to choose the variant that makes you write less code and is more robust and scalable.

0

精彩评论

暂无评论...
验证码 换一张
取 消