How to find out IDs or names of preloaded system drawables (bitmaps) from memory dump

烂漫一生 提交于 2019-12-03 08:09:52

This picture from android.jar, which you have to include into your project. There are two squares with the vertical gradient. The first - from 0x000000 to 0x272d33, the second - from 0xe8e8e8 to 0xfafafa. You can find them in android.jar/res/drawable-nodpi/background_holo_dark.png and background_holo_light.png. Of course, you can get different results depending on your Android SDK version.

I would guess they stay in memory because they are the default backgrounds for activities. Try specifying a different background in your theme and see if they are still there.

The preloaded drawables are loaded by Zygote.

ZygoteInit#preloadResources()

    /**
 * Load in commonly used resources, so they can be shared across
 * processes.
 *
 * These tend to be a few Kbytes, but are frequently in the 20-40K
 * range, and occasionally even larger.
 */
private static void preloadResources() {
    final VMRuntime runtime = VMRuntime.getRuntime();

    try {
        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);
    }
}

You see, the preloaded drawables are com.android.internal.R.array.preloaded_drawables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!