Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does android:onClick use Java reflection concepts behind the scenes?

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.)

like image 277
xyz Avatar asked Jul 15 '26 15:07

xyz


2 Answers

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.

like image 133
Captain Giraffe Avatar answered Jul 18 '26 05:07

Captain Giraffe


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.

like image 38
x-code Avatar answered Jul 18 '26 04:07

x-code