Reputation: 4473
In Android I have a service (started through standard startService
call). The application is referencing a library JAR file. The first Activity sets a static boolean field to "true", then in the service process, I see that this value is true as well.
How can this be?
The service is started after the value is set -- could it be that the DVM copies the static state when the service process is created, or are static
fields shared between processes? I was under the impression that a separate VM was launched for each process.
Upvotes: 0
Views: 747
Reputation: 4473
Sorry I was tricking myself. Though the service is in a separate process (using android:process
attribute in manifest), I was accidentally calling code which was doing this.
-not a real question-
Upvotes: 0
Reputation: 4802
Assuming your Activity and Service are in the same app, they are running in two separate threads under the same process. Thus, you should expect that they share the same instance of the static variable you are referencing.
Upvotes: 1