主要目标是用我自己的实现覆盖 Android 系统类(活动、视图等)。
http://android-developers.blogspot.com/2011/07/custom-class-loading-in-dalvik.html
ClassLoader 用于实现自定义类加载,加载非系统类(custom class)的工作。
但是当我尝试用我的实现加载 Activity 时 - 它没有加载,因为 ClassLoader 已经在它的缓存中有这个类:
/**
* Returns the class with the specified name if it has already been loaded
* by the virtual machine or {@code null} if it has not yet been loaded.
*
* @param className
* the name of the class to look for.
* @return the {@code Class} object or {@code null} if the requested class
* has not been loaded.
*/
protected final Class<?> findLoadedClass(String className) {
ClassLoader loader;
if (this == BootClassLoader.getInstance())
loader = null;
else
loader = this;
return VMClassLoader.findLoadedClass(loader, className);
}
如何更改类加载器以注入我自己的类而不是系统?