缓存设置多少合适呢,一般情况下,设置为当前可用内存的8分之1,那么就需要先获取当前可用内存是多少,通过以下代码可以知道当前缓存的大小:

final int memClass = ((ActivityManager)getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();

得到当前缓存的大小后,即可对缓存的大小进行设置,代码如下:

public class KaleApplication extends Application{    
    /**
     * @description 
     *
     * @param context
     * @return 得到需要分配的缓存大小,这里用八分之一的大小来做     */
    public int getMemoryCacheSize() {        // Get memory class of this device, exceeding this amount will throw an        // OutOfMemory exception.
        final int memClass = ((ActivityManager)getSystemService(Context.ACTIVITY_SERVICE)).getMemoryClass();        // Use 1/8th of the available memory for this memory cache.
        return 1024 * 1024 * memClass / 8;
    }
}