Someone Somewhere
Someone Somewhere

Reputation: 23787

in Android, when a service and activity use the same static class, is the class 'created' twice?

this is just a general knowledge question - out of curiosity...

In Android, when an activity and a service use the same static class (i.e. singleton) does the service end up getting its own 'version' of the class ?

For example, I put all of my global constants into a static class. Are these memory locations created once for activities and again for separate processes such as a service ?

Upvotes: 3

Views: 1177

Answers (1)

Brian Dupuis
Brian Dupuis

Reputation: 8176

No. A single process with a single, unified memory space is created for your activities and services so there will only be one instance of your static class. Note that this is the default behavior and there are ways to, for instance, have your service run in a different process. Then all bets are off and static variables are almost certainly not the best path forward for your implementation.

Upvotes: 2

Related Questions