preloadClasses看起来很简单,但是实际上它有很多的类需要加载。可以查看一下/frameworks/base/preloaded-classes文件,这里面都是需要预加载的类。
接下来,分析一下preloadResources函数的源码:
- private static final boolean PRELOAD_RESOURCES = true; private static void preloadResources()
- { final VMRuntime runtime = VMRuntime.getRuntime();
- Debug.startAllocCounting();
- try { System.gc();
- runtime.runFinalizationSync(); mResources = Resources.getSystem();
- mResources.startPreloading(); if (PRELOAD_RESOURCES) {
- Log.i(TAG, "Preloading resources...");
- long startTime = SystemClock.uptimeMillis(); TypedArray ar = mResources.obtainTypedArray(com.android.internal.R.array.preloaded_drawables);
- int N = preloadDrawables(runtime, ar); ar.recycle();
- Log.i(TAG, "...preloaded " + N + " resources in " + (SystemClock.uptimeMillis()-startTime) + "ms.");
- startTime = SystemClock.uptimeMillis(); ar = mResources.obtainTypedArray(com.android.internal.R.array.preloaded_color_state_lists);
- N = preloadColorstateLists(runtime, ar); ar.recycle();
- Log.i(TAG, "...preloaded " + N + " resources in " + (SystemClock.uptimeMillis() - startTime) + "ms."); }
- mResources.finishPreloading(); } catch (RuntimeException e) {
- Log.w(TAG, "Failure preloading resources", e); } finally {
- Debug.stopAllocCounting(); }
- }










