Service started but not shown in setting -> running services

Viewed 706

I have a android service extends from Service and onStartCommand is return START_STICKY. The service is self running service and no one bind on it.

In my MainActivity, I am using

Intent startService = new Intent(getApplicationContext(), MyService.class);
startService(startService);

Everything is working fine except in Setting -> Running Service 'show cached process' tab not shown anything for my application but in 'cached background process' tab show "Cached services in use". I doubt that why no shown in 'show cached process' tab but I see other app has shown?

1 Answers

The reason is that your service is running on the same process as the application. If you set android:process=":yourServiceName" in the manifest file, your service will start a new process and you can see your service.

Also, do check if your service is actually running using this method

private boolean isMyServiceRunning(Class<?> serviceClass) {
    ActivityManager manager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
        if (serviceClass.getName().equals(service.service.getClassName())) {
            return true;
        }
    }
    return false;
}
Related