What would be the best way to check if an Android Service is running? I am aware of the ActivityManager
API, but it seems like the use of the API is not advised for the scenarios similar to mine (source). I am also aware of the possibility of using global/persistent variables to maintain the state of a service.
I have tried to use bindService
with flags set to 0
, but I got the same problems as the person on the source link (the only exception was, I was trying the bindService
with a local service).
The following call
getApplicationContext().bindService(new Intent(getApplicationContext(),
MyService.class), mServiceConnection, 0);
always returns true, but does not get connected. Is this the expected behaviour? It seems to me bindService
should return false if the service is not already running (it is not, I have checked that) or if the BIND_AUTO_CREATE
flag is not set (again, it is not).