title: How to check whether a service is running or not by other app?
body: <p>I have an app called "ABC" and a class named as "Notification Service" in which i start this service immediately when its activity on create called and i have another app called "SMS". what i want "SMS" app will check whether "Notification Service" is running in background or not if not running then i have to start same service from "SMS" app.Please let me know.</p>
  
  <p>code for service:-</p>
  
  <pre><code>private String m_szMobileNumber;
  private String m_szEncryptedPassword;
  private String TAG = CDealsNotification.class.getSimpleName();
  
  @Nullable
  @Override
  public IBinder onBind(Intent intent) {
      return null;
  }
  
  @Override
  public void onCreate() {
      super.onCreate();
  }
  
  @Override
  public void onStart(Intent intent, int startId) {
      super.onStart(intent, startId);
      CLoginSessionManagement m_oSessionManagement = new CLoginSessionManagement(getApplicationContext());// crating object of Login Session
      HashMap&lt;String, String&gt; user = m_oSessionManagement.getLoginDetails();// get String from Login Session
      m_szMobileNumber = user.get(CLoginSessionManagement.s_szKEY_MOBILE).trim();// getting password from saved preferences..........
      m_szEncryptedPassword = user.get(CLoginSessionManagement.s_szKEY_PASSWORD).trim();// getting mobile num from shared preferences...
  
      final Handler handler = new Handler();
      Timer timer = new Timer();
      TimerTask doServerRequest = new TimerTask() {
          @Override
          public void run() {
              handler.post(new Runnable() {
                  public void run() {
                      try {
                          initialGetData();
                      } catch (Exception e) {
                          // TODO Auto-generated catch block
                          e.printStackTrace();
                      }
                  }
              });
          }
      };
      timer.schedule(doServerRequest, 0, 50000); //execute in every 50000 ms
  }
  
  private void initialGetData() {
      try {
          String json;
          // 3. build jsonObject
          final JSONObject jsonObject = new JSONObject();// making object of Jsons.
          jsonObject.put(ServerRequestKeyStorage.s_szAGENT_CODE, m_szMobileNumber);// put mobile number
          jsonObject.put(ServerRequestKeyStorage.s_szPASSWORD, m_szEncryptedPassword);// put password
          jsonObject.put(ServerRequestKeyStorage.s_szRECORD_COUNT, "5");// put record count
          jsonObject.put(ServerRequestKeyStorage.s_szLAST_COUNT, "0");// put last count
  
          json = jsonObject.toString();// convert Json object to string
  
          Log.e(TAG, "Server Request:-" + json);
          final String m_DealListingURL = APIStorage.IREWARDS_URL + APIStorage.s_szDEALLISTING_URL;
          JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, m_DealListingURL, jsonObject, new Response.Listener&lt;JSONObject&gt;() {
              @Override
              public void onResponse(JSONObject response) {
                  Log.e(TAG, "Server Response:-" + response);
                  try {
                      int nResultCodeFromServer = Integer.parseInt(response.getString(ServerResponseStorage.s_szRESULT_CODE));
                      if (nResultCodeFromServer == CStaticVar.m_kTRANSACTION_SUCCESS) {
                          //Creating Intent for notification
                          Intent resultIntent = new Intent(getApplicationContext(), AppHomeScreenActivity.class);
  
                          TaskStackBuilder stackBuilder = TaskStackBuilder.create(getApplicationContext());
                          stackBuilder.addParentStack(CRewardMain.class);
                          stackBuilder.addNextIntent(resultIntent);
                          //Initialize PendingIntent
                          PendingIntent resul = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
                          // Showing Notification
                          Notification.showNotification(getApplicationContext(), "Earn points", "Earn reward points and Get a chance to win Rs.250 on weekly contest.", resul, 100);
                      }
  
                  } catch (JSONException e) {
                      e.printStackTrace();
                  }
              }
          }, new Response.ErrorListener() {
              @Override
              public void onErrorResponse(VolleyError error) {
                  Log.e(TAG, "Server error:-" + error);
              }
          });
          RequestQueue requestQueue = Volley.newRequestQueue(getApplicationContext());
          requestQueue.add(jsonObjectRequest);
      } catch (JSONException e) {
          e.printStackTrace();
      }
  }
  </code></pre>
  
  <p>}</p>