title: Get current fragment from Service
body: <p>I'm trying to get the current fragment from a Service but I'm getting null.</p>
  
  <p>Service:</p>
  
  <pre><code>MainActivity mainActivity=new MainActivity();
  FragmentManager fm= mainActivity.getSupportFragmentManager();
  Fragment currentFragment = fm.findFragmentByTag("myFragment");
  if (currentFragment.isVisible()){
      // send some stuff 
  } else {
          // create notification
  }
  </code></pre>
  
  <p>Basically I need it to send some values if it's visible or if it's not visible to create a notification. Both are working but when I put my logic in there I get null value for the currentFragment.
  Thanks.</p>