Ward- This is not a Dalvik bug. It's a common side-effect of the way Java inner classes work. Not only will your approach not work properly, but it will cause significant memory leaks (the back-trail of outer-class "this" pointers will prevent the previous Activity from being GC'd).
If you don't already have it, I would encourage you to check out "Effective Java", which is loaded with tips that can steer you away from situations like this. <http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683/> Back to your specific problem. The most important rule of thumb is that inner classes should be "static" whenever possible - this breaks the hidden linkage with the outer class, and makes them more appropriate for moving around. Depending on the complexity of what you're doing, you may also need to break it into two inner classes - one that's static for holding the data-to-be-shared, and one that's not static for doing things with its outer class. There are other solutions, but I would start there. --Andy On Wed, Dec 10, 2008 at 8:20 AM, Ward Willats <[EMAIL PROTECTED]> wrote: > > Hello. > > On the G1.... > > Say you have a custom view class. > > It has an inner-class with some view state. This inner-class > references some variables in the outer class. The outer-class > instances the inner-class and holds a reference to it. > > Now, say you clone the inner class reference, and pass the copy to a > new instance of the custom view in another activity (so the new view > instance can pick up where the previous one left off). > > In the new activity, new view instance, inner-class view state clone, > you find that the "this pointer" is that of the OLD view parent, and > that attempts to access variables in the outer class access variables > in the OLD outer class instance. > > In the debugger, it appears there is an anonymous "pointer" > ("Outer-class$0") to the enclosing outer-class that was not cloned / > setup properly by the native clone helper and runtime. It still > points back to the old outer-class. > > Not being an Uber Java Wonk(tm), you rewrite your code to not use > inner-classes, and all works well. But you decide to write to the > list and see if this is maybe a Dalvik bug, or just something you > shouldn't try to do in the first place. > > -- Ward > > > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en -~----------~----~----~----~------~----~------~--~---

