Reputation: 4289
I have a service ('Aservice') that is declared in manifest as
<service android:name=".Aservice" android:process=":my_process" > </service>
and I want to know how to stop this service from another service (let 'Bservice') of the application. I had tried like this, the service 'Aservice' finds its process id using
int pid = android.os.Process.myPid();
and then it sends its Id to another service ('Bservice') specially designated to stop itself (the service Aservice), the 'Bservice' call this code
android.os.Process.killProcess(pid);
Where 'pid' is the Aservice service Process Id which was sended, but 'Bservice' is unable to stop the service 'Aservice' and I can see the service listed in phone setting->running service. Also this code
ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE))
{
sClassName = service.service.getClassName();
if (sClassName.contains("com.pkg.Rand.Aservice"))
{ return true; }
}
return false;
is returning True. Its necessary to run the service as separate process to prevent slow down of application as it senses location. Please advice on how to stop service running as separate process from some other service in different process.
Any help is highly appreciated.
Upvotes: 1
Views: 3375
Reputation: 91331
You started your service with Context.startService(), so you stop it with Context.stopService(). It doesn't matter what process it is running in.
Upvotes: 6