title: ViewPager not getting updated using FragmentStatePagerAdapter
body: <p>I've a two <code>fragments</code>, <code>Fragment A</code> and <code>Fragment B</code>. <code>Fragment A</code> lists all products and <code>Fragment B</code> shows detail about the product and its images.</p>
  
  <p><code>Fragment A</code> calls <code>Fragment B</code> and <code>Fragment B</code> fetches data from web service and sets to <code>ViewPager</code> using <code>Adapter</code>. Initially it displays correct image but thereafter it always have the same image.</p>
  
  <p>If we fire <code>adapter.notifyDataSetChanged()</code> from any click event in Fragment B then it works perfectly but we have to display as soon as Fragment B is visible</p>
  
  <p>Please look at the code.</p>
  
  <pre><code> public class ImageAdapter extends FragmentStatePagerAdapter {
  
  private List&lt;String&gt; pImageURL;
  
  public ImageAdapter(FragmentManager fm, List&lt;String&gt; imageURL) {
      super(fm);
      // TODO Auto-generated constructor stub
  
      pImageURL = imageURL;
      Utility.showLog("PagerAdapter URL", pImageURL.toString());
  }
  
  @Override
  public Fragment getItem(int position) {
      // TODO Auto-generated method stub
  
      String imageURL = pImageURL.get(position);
  
      PImageFragment imageFragment = (PImageFragment) PImageFragment.getInstance();
      imageFragment.setProductImage(imageURL);
      return imageFragment;
  }
  
  @Override
  public int getItemPosition(Object object) {
  
      PImageFragment pFragment = (PImageFragment) object;
      String URL = pFragment.getProductImage();
  
      int position = pImageURL.indexOf(URL);
  
      if (position&gt;=0)
          URL = pImageURL.get(position);
  
      if (position&gt;=0)
          return position;
      else
          return POSITION_NONE;
  
  }
  
  @Override
  public int getCount() {
      // TODO Auto-generated method stub
      return pImageURL.size();
     }
  }
  </code></pre>
  
  <h2>Fragment B</h2>
  
  <pre><code>   // Image Loading Process
  
      String p_images = model.getProdutImageURL();
  
      imageUrl = new ArrayList&lt;String&gt;();
  
  
      if (p_images.contains(","))
          imageUrl.addAll(Arrays.asList(p_images.split(",")));
      else
          imageUrl.add(p_images);
  
      mAdapter = new ImageAdapter(getChildFragmentManager(), imageUrl);
      vPager.setPageTransformer(true, new DepthPageTransformer());
      vPager.setAdapter(mAdapter);
  
      mAdapter.notifyDataSetChanged();
  </code></pre>
  
  <h2>PImage Fragment</h2>
  
  <pre><code>public class PImageFragment extends Fragment {
  
  private static final String TAG = "Product_Images_Fragment";
  private View rootView;
  
  private ImageView ivProductImage;
  private String imageURL;
  
  @Override
  @Nullable
  public View onCreateView(LayoutInflater inflater, ViewGroup container,
                           Bundle savedInstanceState) {
      // TODO Auto-generated method stub
  
      rootView = inflater.inflate(R.layout.p_detail_images, container, false);
  
      bindComponents(rootView);
      loadImages(imageURL);
      return rootView;
  
  }
  
  public static Fragment getInstance() {
  
      Fragment fragment = new PImageFragment();
      return fragment;
  }
  
  public void setProductImage(String image_url) {
  
      imageURL = image_url;
      Utility.showLog(TAG + "Received URL : ", imageURL.toString());
  
  }
  
  public String getProductImage() {
  
      return imageURL;
  }
  
  private void bindComponents(View v) {
      // TODO Auto-generated method stub
  
      ivProductImage = (ImageView) v.findViewById(R.id.ivProductImage);
  }
  
  private void loadImages(String image_url) {
  
  
      Utility.showLog(TAG,
              "http://baryapp.com/kickzexchange/assets/products/" + image_url);
  
      final ProgressBar pBar = (ProgressBar) rootView
              .findViewById(R.id.pBarLoader);
      pBar.setVisibility(View.VISIBLE);
  
      ImageLoader imgLoader = VolleySingleton.getInstance().getImageLoader();
  
      imgLoader.get("http://baryapp.com/kickzexchange/assets/products/"
              + image_url, new ImageListener() {
  
          @Override
          public void onErrorResponse(VolleyError vError) {
              // TODO Auto-generated method stub
  
              Utility.showLog(TAG, vError.getLocalizedMessage() + "");
          }
  
          @Override
          public void onResponse(ImageContainer response, boolean result) {
              // TODO Auto-generated method stub
  
              if (response.getBitmap() != null) {
  
                  ivProductImage.setImageBitmap(response.getBitmap());
                  pBar.setVisibility(View.GONE);
  
              }
          }
      });
  }
  
  
  }
  </code></pre>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>    // This is how fragment A calls fragment B
     ProductDetail pDetail = new ProductDetail();
  
      Bundle bundle = new Bundle();
      bundle.putString("product_id", productList.get(position).getProductID());
      bundle.putString("product_title", productList.get(position).getProductTitle());
  
      pDetail.setArguments(bundle);
  
      ((MyTabActivity) mActivity).navigateFragment(Utility.BUY_TAB, pDetail,
              true);
  </code></pre>
  
  <p><strong>LATEST UPDATE</strong></p>
  
  <pre><code>    public void navigateFragment(String tag, Fragment fragment,
                               boolean shouldAdd) {
  
      FragmentManager manager = getSupportFragmentManager();
      FragmentTransaction ft = manager.beginTransaction();
  
  
      if (shouldAdd)
          mStacks.get(tag).push(fragment); // push fragment on stack
  
  
      if (mCurrentFragment != null) {
          saveFragmentState(mCurrentFragment.getClass().getName(), mCurrentFragment);
      }
  
      mCurrentFragment = fragment;
      restoreFragmentState(fragment.getClass().getName(), fragment);
  
  
      ft.replace(android.R.id.tabcontent, fragment);
  
      ft.commit();
  
  
  }
  
   @Override
  protected void onSaveInstanceState(Bundle outState) {
      // TODO Auto-generated method stub
      super.onSaveInstanceState(outState);
  
      Bundle fragmentStates = new Bundle(mFragmentStates.size());
  
      for (Map.Entry&lt;String, Fragment.SavedState&gt; entry : mFragmentStates.entrySet()) {
          fragmentStates.putParcelable(entry.getKey(), entry.getValue());
      }
      outState.putParcelable(KEY_FRAGMENT_STATES, fragmentStates);
  }
  
  
  private void saveFragmentState(String id, Fragment fragment) {
  
      Fragment.SavedState fragmentState =
              getSupportFragmentManager().saveFragmentInstanceState(fragment);
      mFragmentStates.put(id, fragmentState);
  
  
  }
  
  private void restoreFragmentState(String id, Fragment fragment) {
  
      Fragment.SavedState fragmentState = mFragmentStates.remove(id);
  
      if (fragmentState != null) {
  
          if (!fragment.isAdded())
              fragment.setInitialSavedState(fragmentState);
  
      }
  
  }
  </code></pre>
  
  <p>Any help/idea is highly appreciated.</p>