How can I check whether the Service is running in the Background or not?

When I was dealing with the Services in Android, I found out that, we start a service whenever for the first time an application is created and started. But the next time, when we open the same application, then also the Service gets started.
So, I searched for this"How can i check that whether Service is running in Background or not?". And I found a great solution too.
  1. private boolean isMyServiceRunning() {    
  2.     ActivityManager manager = (ActivityManager)getSystemService(ACTIVITY_SERVICE);    
  3.     for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {    
  4.        if (YourService.class.getName().equals(service.service.getClassName())) {    
  5.            return true;    
  6.        }    
  7.     }    
  8.     return false;    
  9. }   
Here, "YourService" is the name of the class of your service. This way you can check whether your service is running in the Background or not.