Beispiel #1
0
  /**
   * Find and return an existing ImageCache stored in a {@link RetainFragment}, if not found a new
   * one is created using the supplied params and saved to a {@link RetainFragment}.
   *
   * @param activity The calling {@link FragmentActivity}
   * @param cacheParams The cache parameters to use if creating the ImageCache
   * @return An existing retained ImageCache object or a new one if one did not exist
   */
  public static ImageCache findOrCreateCache(
      final FragmentActivity activity, ImageCacheParams cacheParams) {

    // Search for, or create an instance of the non-UI RetainFragment
    final RetainFragment mRetainFragment =
        RetainFragment.findOrCreateRetainFragment(activity.getSupportFragmentManager());

    // See if we already have an ImageCache stored in RetainFragment
    ImageCache imageCache = (ImageCache) mRetainFragment.getObject();

    // No existing ImageCache, create one and store it in RetainFragment
    if (imageCache == null) {
      imageCache = new ImageCache(activity, cacheParams);
      mRetainFragment.setObject(imageCache);
    }

    return imageCache;
  }