title: How to correct add a listener to a Fragment
body: <p>I got two Fragments (basic-setup) with a FragmentPagerAdapter for use in a TabLayout.</p>
  
  <pre><code>tabLayout.setupWithViewPager(myViewPagerWithAdapter);
  </code></pre>
  
  <p>My Adapter takes an array of Fragments and titles as argument (also the FragmentManger for the super call).</p>
  
  <pre><code>MyViewPagerAdapter adapter = new MyViewPagerAdapter(getSupportFragmentManager() ,fragments, titles);
  </code></pre>
  
  <p>My Fragments (indeed 2) got a WebView in their xml file. To use the WebViews outside the fragments (it's kinda odd to code the control of the WebViews inside fragments, because the MainActivity is mainly involved with my user interaction). To know when my WebViews in the fragments were inflated, I added a simple interface, called OnFragmentCreatedListener, which is triggered in <code>public void onActivityCreated(Bundle savedInstanceState)</code> of the fragments. I add the listener through following way:</p>
  
  <pre><code>private OnFragmentCreatedListener listener;
  ...
  public void addOnFragmentCreatedListener(OnFragmentCreatedListener listener) {
      this.listener = listener;
  }
  </code></pre>
  
  <p>In my MainActivity I add this listener like this:</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity implements OnFragmentCreatedListener {
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      ...
      MyFragment fragment = MyFragment.newInstance();
      ...
      fragment.addOnFragmentCreatedListener(this);
      ...
  }
  
  @Override
  public void onFragmentCreatedListener() {
      // Do my stuff
  }
  </code></pre>
  
  <p>Now when the screen rotates and the activity is restarted, the listener in the fragment stays null (wasn't initialized). Now I don't know what to do, because I don't understand this behavior. The code should do the same like in the first <code>protected void onCreate(Bundle savedInstanceState)</code> of the MainActivity. It's adding the listener but it stays null (like wtf?).</p>
  
  <p>Thank you for spending your time!</p>