title: Check if Android foreground service is active on app restart?
body: <p>I have a sensor which connects with my app via bluetooth. I have created a Foreground service which keeps the app active and connected with the sensor even after user close the app. To stop the Foreground service, user relaunch the app and stops the foreground service.</p>
  
  <p>All the above is done perfectly and works fine for <strong>NOW</strong>.</p>
  
  <p>My problems are - </p>
  
  <p>There is a play and pause button to start and stop the service. Once started, the icons changes but relaunching the app after closing the app completely (without stopping the foreground service), app doesn't change. Of course it doesn't change because I have no idea how to check if service is still running in the foreground or not. </p>
  
  <p>Yes, I have read all the previous answers and most of them are either deprecated or doesn't work anymore. </p>
  
  <p>Since Commonsware is asking for the link for all the posts I have read so far, here you go - </p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/2166961/determining-the-current-foreground-application-from-a-background-task-or-service">Determining the current foreground application from a background task or service</a></li>
  <li><a href="https://stackoverflow.com/questions/41295924/how-to-check-is-app-in-foreground-from-service/41296273">How to check is app in foreground from service?</a></li>
  <li><a href="https://stackoverflow.com/questions/8489993/check-android-application-is-in-foreground-or-not">check android application is in foreground or not?</a></li>
  <li><a href="https://stackoverflow.com/questions/53761074/check-if-foreground-service-is-running-in-android-oreo">Check if Foreground service is running in Android OREO</a></li>
  <li><a href="https://stackoverflow.com/questions/6452466/how-to-determine-if-an-android-service-is-running-in-the-foreground?noredirect=1&amp;lq=1">How to determine if an Android Service is running in the foreground?</a></li>
  </ol>