title: How to pass data into fragment dynamically loaded into current activity
body: <p>My activity contains "FrameLayout" element only.</p>
  
  <p>In its 'onCreate' method I dynamically load fragment:</p>
  
  <pre><code>@Override
  public void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
  
          UsersListFragment fragment = new UsersListFragment();
  
          FragmentManager fm = getSupportFragmentManager();
          FragmentTransaction ft = fm.beginTransaction();
          ft.add(R.id.fragment_container, fragment);
          ft.commit();
  }
  </code></pre>
  
  <p>On some event my fragment communicates back to activity and I need to instantiate another fragment and pass some data to it. I do it in the activity by implementing special interface that is in turn called by fragment. It looks like this way:</p>
  
  <pre><code>@Override
  public void onUserSelected(long userId) {
  
          UserDetailsFragment fragment = new UserDetailsFragment();
  
          FragmentManager fm = getSupportFragmentManager();
          FragmentTransaction ft = fm.beginTransaction();
          ft.replace(R.id.fragment_container, fragment);
          ft.addToBackStack(null);
          ft.commit();
  
          fragment.updateUser(userId);
  }
  </code></pre>
  
  <p>As a result, "fragment.updateUser(userId);" is called way to early (fragment is not initialized yet, it is not attached to activity).</p>
  
  <p>Question: what is the proper way to pass data into the fragment?</p>
  
  <p>Thanks a lot in advance. Any thoughts are greatly appreciated.</p>
  
  <p>P.S. I've seen a lot of examples that show how to load fragments, but was not able to find those that show how to pass data...</p>