title: How to start a service from an activity in android?
body: <p>am too much confused in starting a background service from an activity and am providing the code which i used to start the service from an activity.</p>
  
  <pre><code>private boolean isMyServiceRunning() {
      ActivityManager manager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
      Log.v("Running activities", manager.toString());
      for (RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
   if ("com.*.*.service.Service".equals(service.service.getClassName())) {
       return true;
         }
      }
       Log.v("Currently running services in andorid phone", "other services");
      return false;
  }
  </code></pre>
  
  <p>Above code is to check whether the service is running or not.If it is not means am doing this </p>
  
  <pre><code>if(isMyServiceRunning()) {
                            System.out.println("Service is running");
                          } else {
                            System.out.println("Service is not running");
                            Intent serviceIntent = new Intent();
                            serviceIntent.setAction("com.*.*.service.Service");
                            startService(serviceIntent);
                          }
  </code></pre>
  
  <p>Suggest your answers and solutions to solve this problem.</p>