The question has been asked in many forms and for many times here and here; But I want to confirm one thing and my questions is very simple: Does android:onClick use Java reflection?
Since Java reflection slows down the performance as explained here, I would never like to code in inefficient manner.
I just want a simple answer: yes (only if you are sure about that) or no?
EDIT:
There are many answers on SO conflicting the understanding:
For example, See this one and this one. Both have accepted answers and both are saying two different things. (thats only why I posted the question.)
Indeed it does use reflection to bind the method("methodName") to the handler. This is a one time deal while inflating the XML and does not affect performance in any meaningful way. The XML inflation is in itself is a rather costly parse,
(Per http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.1_r2/android/view/View.java#2017)
Besides this, it is exactly like the doing it in code.
Until the delay in responding to a button click reaches about 1/10th of a second, humans perceive it as instantaneous, so optimizing reflection out of a button click response doesn't matter.
You should not worry about this kind of issue so that optimization effort can focus on the code where there is a measurable performance problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With