I have a library that loads classes from it's jar dynamically but has to do so with the ClassLoader provided by the "context" object for the application it is packaged with and being called from. Is there a way to get the context or class loader from within a process from the library code with no direct reference passed in to the library call?
I guess what I am looking to do is this:
class SomeLibraryClass {
static final boolean isAndroid_;
static {
if (System.getProperty("java.vm.name").equalsIgnoreCase("Dalvik")) {
isAndroid_ = true;
} else {
isAndroid_ = false;
}
}
static ClassLoader getClassLoader() {
if(isAndroid_) {
return(getClassLoaderForVMProcessAppContext());
}
return(getClassLoaderForUnixWindowsMacJavaProcess());
}
private static ClassLoader getClassLoaderForVMProcessAppContext() {
/* do something here that requires no static linkage, imports
* etc to any android specific classes or jars to get
* class loader for the current process' application context.
* so this library can be used on all platforms
*/
}
}