title: How to correctly get data from fragment to parent activity?
body: <p>I have activity that contains A and B fragment. I used FrameLayout and BottomNavigation. I use following method to change fragment.</p>
  
  <pre><code>FragmentTransaction transaction =getSupportFragmentManager().beginTransaction();
  transaction.replace(R.id.frame, selectedFragment);
  transaction.commit();
  </code></pre>
  
  <p>And i have one menu in activity which contains printer and mail. When i click printer or mail button from Activity. Activity have to get data from Fragment A or Fragment B. It's kind of sale process.</p>
  
  <p>If Sale process is success i clear data of Fragment A and B. B contains lot of items. A contains one item.</p>
  
  <p>My problem is I use Global variables to pass data.</p>
  
  <p>Fragment B:</p>
  
  <pre><code>public static List&lt;Product&gt; ProductList = new ArrayList&lt;&gt;();
  public static List&lt;Product&gt; itemSaleProductList = new ArrayList&lt;&gt;();
  public static double itemSaleTotalPrice = 0;
  </code></pre>
  
  <p>Fragment A:</p>
  
  <pre><code>public static Product quickSale = null;
  </code></pre>
  
  <p>After user click item i save data. And when user click printer button it gets data from Global variables. Also If global variables have a value, Fragment B and A have to get that values.</p>
  
  <p>It works. But Sometimes it can't get values. So How to get data correctly from activity?</p>