【发布时间】:2012-01-13 22:18:06
【问题描述】:
主要目标是用我自己的实现覆盖 Android 系统类(Activity、View 等)。
http://android-developers.blogspot.com/2011/07/custom-class-loading-in-dalvik.html
实现了用于自定义类加载的ClassLoader,加载非系统类(自定义类)工作。
但是当我尝试用我的实现加载 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);
}
如何更改类加载器以注入我自己的类而不是系统?
【问题讨论】:
标签: java android reflection classloader dynamic-class-loaders