/** * Find and return an existing ImageCache stored in a {@link ImageCache.RetainFragment}, if not found a new * one is created using the supplied params and saved to a {@link ImageCache.RetainFragment}. * * @param fragmentManager The fragment manager to use when dealing with the retained fragment. * @param memCacheSizePercent The cache size as a percent of available app memory. * @return An existing retained ImageCache object or a new one if one did not exist */ public static ImageCache getInstance( FragmentManager fragmentManager, float memCacheSizePercent) { // Search for, or create an instance of the non-UI RetainFragment final RetainFragment mRetainFragment = findOrCreateRetainFragment(fragmentManager); // 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(memCacheSizePercent); mRetainFragment.setObject(imageCache); } return imageCache; }