On Mar 9, 7:17 pm, Greg Krimer <gkri...@gmail.com> wrote:
> I have been finding it convenient to extend Handler in many of my
> activities to handle messages specific to the activity. The handler
> sublass is an inner class of the activity and needs to access its
> state. I am wondering if there is any performance difference between
> making the handler subclass static and passing in the activity
> explicitly in its constructor or making the subclass an "instance
> class" and letting the vm worry about my accessing members of the
> containing activity.

There's no real difference between explicitly and implicitly passing
the outer-class reference around.  Your example above is essentially
doing what javac does automatically.

Static inner classes have some useful properties, e.g. you know
they're not modifying state in the parent, and you can use
Class.newInstance() with them.  There's no performance magic though.

If you're really curious, write it both ways in trivial source files,
compile them, then view them with "javap -private -verbose <Class>" or
"dx --dump <Class.class>".  They should look about the same.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers-unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to