DexClassLoader - adding functionality
I'm doing some testing with DexClassLoader, to see if it's possible to
"update" my app with new functionality. Currently I've got this method for
testing, which works with testClass and running the test() method.. What I
would like to know, is how could I "replace" or "update" and already
existing class.. ? Any ideas or other suggestions are welcome.
Method:
public static void loadExtLib(String pathDexFile, Context ctx) {
String temp = ctx.getDir("temp", 0).toString();
DexClassLoader classLoader = new DexClassLoader(pathDexFile,
temp, null, ctx.getClass().getClassLoader());
String testClass = "com.mystudio.myapp.TestClass";
Class<?> libProviderClass = null;
try {
libProviderClass = classLoader.loadClass(testClass);
} catch (ClassNotFoundException e1) {
e1.printStackTrace();
}
try {
Method m = libProviderClass.getDeclaredMethod("test", null);
try {
m.invoke(libProviderClass, null);
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}
} catch (NoSuchMethodException e1) {
e1.printStackTrace();
}
Log.v("loadClass", "loaded: " + testClass);
}
No comments:
Post a Comment