• After 15+ years, we've made a big change: Android Forums is now Early Bird Club. Learn more here.

Apps Kill Button Listeners???

Laxidasical

Newbie
Developing on some other platforms require you to kill your own button listeners (or any other listener types for that matter) in order to ensure you aren't creating memory leaks. None of the examples I've seen on how to implement button listeners in Android do this though.

Does Android do it automatically? If so, is it done when the view is no longer in focus or when the app itself is destroyed?

Just curious...
 
Developing on some other platforms require you to kill your own button listeners (or any other listener types for that matter) in order to ensure you aren't creating memory leaks. None of the examples I've seen on how to implement button listeners in Android do this though.

Does Android do it automatically? If so, is it done when the view is no longer in focus or when the app itself is destroyed?

Just curious...

Just an aside. HAC (HyperNext Android Creator) doesn't have any button listeners, canvas listeners etc because it would have created a bloat in its runtime engine and that would be really bad for performance on a mobile device. Initially we tried the Listener route but the overheads were too large. Instead it uses its own GUI that still aims to look like Android but only reacts when an event occurs such as the user touching the screen or a relevant command being called.

There are many interesting articles on the web about this- a Google search for "Listeners in Java and their overheads".By the way. I don't have a clue how the Dalvik Machine does this stuff, just that using Listeners for cloned controls was very slow for us.
 
Just an aside. HAC (HyperNext Android Creator) doesn't have any button listeners, canvas listeners etc because it would have created a bloat in its runtime engine and that would be really bad for performance on a mobile device. Initially we tried the Listener route but the overheads were too large. Instead it uses its own GUI that still aims to look like Android but only reacts when an event occurs such as the user touching the screen or a relevant command being called.

There are many interesting articles on the web about this- a Google search for "Listeners in Java and their overheads".By the way. I don't have a clue how the Dalvik Machine does this stuff, just that using Listeners for cloned controls was very slow for us.

I'm not using HAC, I'm developing natively. It sounds like HAC has either a CPU or memory issue of it's own when it comes to listeners.

I do know that Java listeners aren't actually "listening" (constantly running in the background) in a traditional sense, and that they don't take up much memory or CPU usuage after being registered. I'm guessing this is why they don't need to be explicitly killed. Still, it's just weird to me as a developer to leave something like that unchecked. I'm just looking for clarification (and piece of mind! LOL).
 
There is an interesting article about Java Listeners and overheads at the osgi.org website called "Listeners Considered Harmful: The Whiteboard Pattern" that seems to agree with your earlier thoughts about Listeners being killed. It gives some drawbacks of Listeners for mobile devices.

Googling for "Java Listener Overhead" will give you the link.

Of course as Android device hardware performances increase perhaps then this problem will be tend to insignificance.
 
I read that article after your first post. It seems to apply to Java in general rather than Android (I know Dalvik handles things a little differently). Also, it's dated August 2004 which is a full 4 years before Android showed up on a public device (Oct 2008 on the G1). A lot has changed since then, especially with Froyo's release.

I'm not saying for sure the article isn't still valid, but 7 years is an eternity in the land of programming.
 
Back
Top Bottom