title: How to detect when a fragment appears on the screen?
body: <p>How could some part of my code be aware of Fragment instance become visible on a screen?</p>
  
  <p>The following snippet will explain my question.</p>
  
  <pre><code>public class MyApp extends Application {
  public static final String TAG = MyApp.class.getSimpleName();
  
  @Override
  public void onCreate() {
      super.onCreate();
      registerActivityLifecycleCallbacks(new ActivityLifecycleCallbacks() {
          ...
  
          @Override
          public void onActivityResumed(Activity activity) {
             Log.d(TAG, activity.getClass().getSimpleName() + " is on screen");
          }
  
          @Override
          public void onActivityStopped(Activity activity) {
              Log.d(TAG, activity.getClass().getSimpleName() + " is NOT on screen");
          }
  
          ...
      });
  }
  </code></pre>
  
  <p>Here i can track when any activity within my app appears on the screen. Is there any way to extend this approach on Fragments?</p>
  
  <p>Something like
  <code>Activity.getFragmentManager().registerFragmentLifecycleCallbacks();</code></p>
  
  <p><strong>UPD.</strong> I know nothing about activities implementations, do they use fragments at all and how do they use them (injection via xml, ViewPager etc.) The only thing I have within my class is an application context. Let's assume Activity and Fragment implementations are black boxes and i am not able to make any changes.</p>