title: Unable to reuse fragment for usage of LruCache
body: <p>I'm using Google's example for caching bitmap across config changes, almost line-by-line:</p>
  
  <p><a href="http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html#config-changes" rel="nofollow noreferrer">http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html#config-changes</a></p>
  
  <p>I am calling addBitmapToMemoryCache when a field is updated, which is way before the config change (device rotation). However, after putting debug info in findOrCreateRetainFragment:</p>
  
  <pre><code>public static RetainFragment findOrCreateRetainFragment(FragmentManager fm) {
      RetainFragment fragment = (RetainFragment) fm.findFragmentByTag(TAG);
      if (fragment == null) {
          fragment = new RetainFragment();
          Log.w("myapp", "instanciating new retainfragment");
          fm.beginTransaction().add(fragment, TAG).commit();
      } else {
          Log.w("myapp", "using old retainfragment");
      }
      return fragment;
  }
  </code></pre>
  
  <p>The fragment is <strong>always</strong> newly instanciated, so I never get access to the old LruCache, despite <code>setRetainInstance(true)</code>. Is there something wrong with Google's example? I am using the v4 support FragmentManager.</p>
  
  <p>Here's the relevant portion of my onCreate:</p>
  
  <pre><code>RetainFragment retainFragment =
              RetainFragment.findOrCreateRetainFragment(getSupportFragmentManager());
  mMemoryCache = retainFragment.mRetainedCache;
  if (mMemoryCache == null) {
      mMemoryCache = new LruCache&lt;String, Bitmap&gt;(3 * 1024 * 1024) {
          @Override
          protected int sizeOf(String key, Bitmap bitmap) {
              return bitmap.getByteCount() / 1024;
          }
      };
      retainFragment.mRetainedCache = mMemoryCache;
  } else {
      backgroundsByMonth = new ArrayList&lt;&gt;();
      for (int i = 0; i &lt; 12; i++) {
          BitmapDrawable bd = new BitmapDrawable(getResources(), mMemoryCache.get(Integer.toString(i)));
          backgroundsByMonth.add(bd);
      }
  }
  </code></pre>