how expensive findViewById ??

by Alexey » Tue, 14 Apr 2009 00:04:39 GMT


Sponsored Links
 Hi all, trying to find some performance numbers for findViewById -
need to convince  to change bunch of the findViewById for the same
widget to member variable with just one findViewById on create . Or
may be i'm wrong and it's fine ?
--~--~---------~--~----~------------~-------~--~----~



how expensive findViewById ??

by Michael Bollmann » Tue, 14 Apr 2009 00:20:39 GMT


 It depends on how often you call it and what your app is doing anyway.
Now matter how good it's implementation is access to a member variable
is always much faster than a function call.
On the other hand you might not notice any improvement in case your
app does some stuff that takes
1000 times longer than a call to findViewById.

Take a look at this: 
 http://developer.android.com/guide/practices/design/performance.html #samples



--~--~---------~--~----~------------~-------~--~----~


Sponsored Links


how expensive findViewById ??

by Alexey » Tue, 14 Apr 2009 00:43:00 GMT


 yeah, that reference doesn't have number i'm looking for.

On Apr 13, 11:20am, Michael Bollmann



--~--~---------~--~----~------------~-------~--~----~



how expensive findViewById ??

by Michael Bollmann » Tue, 14 Apr 2009 01:09:22 GMT


 I guess findViewById uses some kind of map implementation with O(log
n)
So my guess is that it's about 100-200 compared to 0 when you use
member access.





--~--~---------~--~----~------------~-------~--~----~



how expensive findViewById ??

by Dianne Hackborn » Tue, 14 Apr 2009 02:53:43 GMT


 Actually it's not nearly so smart -- it is just a traversal through the view
hierarchy until it finds a matching id.

As with all things, you should avoid doing this repeatedly if you don't need
to (keep the thing you find in a variable so you don't have to look it up
again).  For more subtle performance questions, the profiler is really what
you need to use.

On Mon, Apr 13, 2009 at 10:09 AM, Michael Bollmann <








-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~



how expensive findViewById ??

by Alexey » Tue, 14 Apr 2009 03:49:23 GMT


 Thanks. that answers my question.







--~--~---------~--~----~------------~-------~--~----~



Other Threads

1. Accessibility question

I have just started looking at android development.  I am blind and trying 
to figure out how to work with the emulator to test things.  Can anyone 
tell me how to get free-eyes to run in the emulator and preferably come up 
when the emulator starts?  I don't know if that will make anything more 
accessible but it is a place to start.


Tom

--

2. Compressing camera image to a certain size

Hello

I am sending images taken from the camera to a server. I want to keep
as high quality as possible but not exceed 1.5MB.

When data from camera is less than 1.5MB i do not process it, but
there are cases when data might be 3, 5 etc.

I have looked around in the BitmapFactory and Bitmap class. Basically
i need to Bitmap.compress with a dynamic quality parameter.

How can I determine which quality to use inorder to get an unknown
image data size to 1.5MB? Or is there an other way to handle this?

Thx for any pointers.

-- 

3. How to make a map move as you drive?

4. bitmap magnification

5. how do i add the content view behind gridview?

6. Optimizing TextView creation

7. How could I be interfering with context menu longclick?