Hi,
I newed a DexClassLoader to load one jar file dynamicly:
DexClassLoader cl = new DexClassLoader("my.jar",
getFilesDir().getAbsolutePath(),
null,
this.getClassLoader());
It is OK to loadClass and execute method with reflection like below:
Class<?> handler = Class.forName(handlerClassName);
Method m = handler.getDeclaredMethod(
"addMyPreferences",
Class.forName("android.content.Context"),
Class.forName("android.preference.PreferenceCategory"),
Class.forName("java.lang.String"));
m.invoke(handler.newInstance(), this, mExtraSettingsCategory,
defaultValue);
I want the new classloader to be the one of my activity so I can new
instance and execute method more easily like below:
HandlerClass hc = new HandlerClass();
hc.addMyPreferences(activity,category,"test");
I think I have to set my cl to be default ClassLoader of Activity.
After googling web, some google guy suggest to use
Thread.currentThread().setContextClassLoader(cl) to achieve similar
thing.
However, it does not work.
I found Thread.currentThread().getContextClassLoader() is different
from Activity.class.getClassLoader().
So event I changed Thread's context classloader, Activity's
classloader is not my cl.
My question is how to change Activity's ClassLoader?
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en