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. MapsActivity has leaked window

Hi,

I want to show route with build-in(OS) MapActivity, I put package and
class name to Intent, and after show Activity.

When I pressed back button when map is starting (Nexus One), I have
exception:

07-26 11:00:46.043: ERROR/WindowManager(637): Activity
com.google.android.maps.MapsActivity has leaked window
com.android.internal.policy.impl.phonewindow$decorv...@439619d8 that
was originally added here
07-26 11:00:46.043: ERROR/WindowManager(637):
android.view.WindowLeaked: Activity
com.google.android.maps.MapsActivity has leaked window
com.android.internal.policy.impl.phonewindow$decorv...@439619d8 that
was originally added here
07-26 11:00:46.043: ERROR/WindowManager(637):     at
android.view.ViewRoot.<init>(ViewRoot.java:214)
07-26 11:00:46.043: ERROR/WindowManager(637):     at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:148)
07-26 11:00:46.043: ERROR/WindowManager(637):     at
android.view.WindowManagerImpl.addView(WindowManagerImpl.java:91)
07-26 11:00:46.043: ERROR/WindowManager(637):     at
android.view.Window$LocalWindowManager.addView(Window.java:409)
07-26 11:00:46.043: ERROR/WindowManager(637):     at
android.app.Dialog.show(Dialog.java:238)
07-26 11:00:46.043: ERROR/WindowManager(637):     at c.N.b(Unknown
Source)
07-26 11:00:46.043: ERROR/WindowManager(637):     at c.m.d(Unknown
Source)
07-26 11:00:46.043: ERROR/WindowManager(637):     at g.G.a(Unknown
Source)
07-26 11:00:46.043: ERROR/WindowManager(637):     at g.w.t(Unknown
Source)
07-26 11:00:46.043: ERROR/WindowManager(637):     at g.G.a(Unknown
Source)
07-26 11:00:46.043: ERROR/WindowManager(637):     at g.z.a(Unknown
Source)
07-26 11:00:46.043: ERROR/WindowManager(637):     at o.T.a(Unknown
Source)
07-26 11:00:46.043: ERROR/WindowManager(637):     at o.T.c(Unknown
Source)
07-26 11:00:46.043: ERROR/WindowManager(637):     at o.T.a(Unknown
Source)
07-26 11:00:46.043: ERROR/WindowManager(637):     at h.O.e(Unknown
Source)
07-26 11:00:46.043: ERROR/WindowManager(637):     at h.O.a(Unknown
Source)
07-26 11:00:46.043: ERROR/WindowManager(637):     at o.T.b(Unknown
Source)
07-26 11:00:46.043: ERROR/WindowManager(637):     at
com.google.googlenav.android.i.a(Unknown Source)
07-26 11:00:46.043: ERROR/WindowManager(637):     at
com.google.googlenav.android.i.b(Unknown Source)
07-26 11:00:46.043: ERROR/WindowManager(637):     at
com.google.googlenav.android.i.a(Unknown Source)
07-26 11:00:46.043: ERROR/WindowManager(637):     at
com.google.googlenav.android.i.a(Unknown Source)
07-26 11:00:46.043: ERROR/WindowManager(637):     at
com.google.android.maps.MapsActivity.c(Unknown Source)
07-26 11:00:46.043: ERROR/WindowManager(637):     at
com.google.googlenav.ui.android.q.run(Unknown Source)
07-26 11:00:46.043: ERROR/WindowManager(637):     at
android.os.Handler.handleCallback(Handler.java:587)
07-26 11:00:46.043: ERROR/WindowManager(637):     at
android.os.Handler.dispatchMessage(Handler.java:92)
07-26 11:00:46.043: ERROR/WindowManager(637):     at
android.os.Looper.loop(Looper.java:123)
07-26 11:00:46.043: ERROR/WindowManager(637):     at
android.app.ActivityThread.main(ActivityThread.java:4203)
07-26 11:00:46.043: ERROR/WindowManager(637):     at
java.lang.reflect.Method.invokeNative(Native Method)
07-26 11:00:46.043: ERROR/WindowManager(637):     at
java.lang.reflect.Method.invoke(Method.java:521)
07-26 11:00:46.043: ERROR/WindowManager(637):     at
com.android.internal.os.ZygoteInit
$MethodAndArgsCaller.run(ZygoteInit.java:791)
07-26 11:00:46.043: ERROR/WindowManager(637):     at
com.android.internal.os.ZygoteInit.main(ZygoteInit.java:549)
07-26 11:00:46.043: ERROR/WindowManager(637):     at
dalvik.system.NativeStart.main(Native Method)

There is my method:

         public static void showRoute(Context context, Address poiAddress,
Location currentLocation) {
                String route = Utils.buildRouteQuery(poiAddress, 
currentLocation);
                try {
                        ComponentName compName = new 
ComponentName(MAPS_PACKAGE_NAME,
MAPS_CLASS_NAME);
                        final Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse(route)).setComponent(compName);
                        context.startActivity(intent);
                } catch(ActivityNotFoundException e) {
                        Toast.makeText(context, 
R.string.ui_cant_find_additional_app,
Toast.LENGTH_SHORT).show();
                } catch(Exception e){
                        Log.e(TAG, "showRoute", e);
                }
        }

What is the best way to run another Activity with intent and intercept
an exception?

Thanks

-- 

2. Android Maps API - TOS/GPS incompatability?

Is it possible to use the Andoid Maps API to retrieve driving
directions from "my current location" to a pre-known destination
without violating the Android Maps API Terms of Service?

According to section 8.7 of the TOS - "use the Service or Content with
any products, systems, or applications for or in connection with (a)
real time navigation or route guidance based on position input from a
sensor (including but not limited to any visual or audible turn-byturn
route guidance);"

I'm not a lawyer, so thus I dont speak legalize...but I would think if
i had a database of pizza parlors, I could make an app that would let
me get driving directions to the closest pizza parlor to my current
location...

...any help here?

-- 

3. Browsable Intent

4. Bluetooth, RFCOMM socket close error ?

5. how do you guys feel about the develop tools?

6. How to determine size of Layout

7. Android Market paid app download errors