It has to do with class loaders is Java and not processes or applications.
Java language: A class is identified by its fully qualified name Java Virtual Machine: A class object is identified by its fully qualified name and defining class loader Instances of classes loaded by the same classloader will definitely see the same static variables. A classloader usually delegates to its parent classloader. If the parent has already loaded the class it will not load it again. This standard behavior can be changed by writing your own class loader. The result is that a hierarchy of classloaders will only load a class once and therefore allocate static variables and run static blocks once. However if you have multiple hierarchies of classloaders you can load the same class multiple times and have static members allocated multiple times. Two class objects defined by different class loaders are different types even if they are generated from the same class file. Instances of classes loaded by the same classloader see the same static variables. A good reference is chapter 6 of Java Reflection in Action by Forman and Forman. On Sunday, December 23, 2012 2:52:16 AM UTC-5, AndroidCompile wrote: > I created two Android applications that share the same user Id > (sharedUserId) as well as the same process. In the first app, on startup, I > set a static int variable to 1 (it's default is 0). In the second app, I > load (using reflection) the same class from the other app and read the > static int variable. I read 0. > > Since both applications run on the same process, I would expect them to > share the same static values, no? Can anyone tell me what the mechanism > underneath does? (are they using, maybe, different apk/dex loaders and that > causes this behavior?) > -- 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