I am starting an android service using,
startService(getApplicationContext(), MyService.class);
I have correctly defined my service in Andr
Since you specified the android:process
attribute in your
element, and its value is not the same as your application package name, that service is actually running in a separate process from the default process for your application. (I don't know if it was intentional, but you also seem to have a typo in the process name.)
If you did not intend to run the service in a separate process (which is rare, and something you should only do if you have a good reason and understand the implications), you should just omit the android:process
attribute in your
element -- this would cause it to run in the same process as the rest of your app.
A little-known and seemingly undocumented behavior of Android is that each process of an application has is own Application
instance. This explains why starting your service created an additional Application
instance.
Also, not only do the 2 processes have their own Application instances, they actually have their own Application classes, since they do not even share the same class loaders. Therefore, even their static variables can have different values.