0

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.

4

2 回答 2

1

假设您的 Activity 和 Service 在同一个应用程序中,它们在同一个进程下的两个独立线程中运行。因此,您应该期望它们共享您引用的静态变量的相同实例。

于 2013-06-14T21:33:21.647 回答
0

对不起,我在欺骗自己。尽管该服务在一个单独的进程中(使用android:process清单中的属性),但我不小心调用了执行此操作的代码。

-不是一个真正的问题-

于 2013-06-14T23:34:49.523 回答