title: How to check if an activity is running in background/foreground from a service?
body: <p>I have created a service which starts from an activity's onCreate and stops on the activity's onDestroy method. Now I have to check from a method of the service that whether the activity is running in foreground/background(for some cases like application is forcefully closed). How can I do that?</p>
  
  <ol>
  <li><p>I need to do this coz as far I know there is no guarantee of calling onDestroy method of an activity if any the application is forcefully closed or any kind of crash. So, my service which starts when my activity launches won't stop after any crash or any forceful closing event.</p></li>
  <li><p>I have seen <a href="https://stackoverflow.com/questions/12172092/check-if-activity-is-running-from-service">this link</a> where foreground activities can be checked. But I need to check a running activity in whatever state (either foreground or background)</p></li>
  </ol>