I'm trying to use reflection to execute a specific method from a class from another package. And this works OK for the following scenario:
- I install the target package and run my app, works ok.
- I un-install the target package and install a different version of the same package it also works fine when I run it from my app.
If I don't uninstall target, but I just drag over apk with a different code in the emulator (same target package), my app executes code from the previous version, but if I would run that other app, I see it's a proper version (code\functionality) installed, how is that possible???
Obviously, I'm missing something, but this is what I have at the moment behind my app button click:
//...
Context packageContext = createPackageContext("com.some.package", Context.CONTEXT_INCLUDE_CODE + Context.CONTEXT_IGNORE_SECURITY);
Class<?> otherPackageClass = packageContext.getClassLoader().loadClass("com.some.package.SomeClassName");
Method someMethod = otherPackageClass.getDeclaredMethod("someMethod");
//...
(com.some.package
is from that other app)
My guess is that it must be something related to this getClassLoader
or createPackageContext
, but not sure what.
Is it cached maybe somehow and if yes, how to force it to always use the last installed version?
I also tried looking for something like hot reloading
for android reflection etc. but I couldn't find anything that could help me solve this problem.
Aucun commentaire:
Enregistrer un commentaire