To determine whether your service is still running, take a look at the answers to this question. Please note that this is different from the getRunningAppProcesses
solution that you linked to.
In the current implementation of your class, isInstanceCreated()
doesn't tell you whether the service is running; it only tells you whether an instance of MyIntentService
exists. The static member instance
will leak the service object if it's not set to null (e.g., in onDestroy()
).
Now, what really happens here if:
1- I call isInstanceCreated() from a BroadcastReceiver regarding GC (my thoughts are when BroadcastReceiver finish and eligible for GC, the IntentService is also eligible for GC)
2- if I call isInstanceCreated() from Application class regarding GC (my thoughts are IntentService is GC when Android kill Application)
Calling isInstanceCreated()
has no effect on GC eligibility because it doesn't create or destroy any references.
3- The accessor of the static class method will hold the reference something..???
I don't know what you mean by "static class method". The reference to MyIntentService
is held by the static member instance
. If you set instance
to null, then MyIntentService
will be GC eligible when the service finishes running and Android removes its own reference(s) to it.
4- [...] When i call isInstanceCreated() are the entire class also taking up memory [...]
When you reference MyIntentService
the first time, the class loader loads the class into memory and allocates memory for its static members. Since you only have two static members in your class, the memory usage will be very low.