0

I'm trying to load external classes dynamically in an Android app, using a proxy object to intercept calls to the methods. For definition, for use a proxy object, classes must implement an interface. I thought if I create a proxy with an interface I will be able to call classes that not implement it directly. I tried use the same package name and interface implemented in the external class, but it doesn't work.

I have tried some solutions, but I'm not able to load classes dynamically because I receive a ClassCastException.

So I want to intercept object calls and do a function that is implemented in a external apk, using DexClassLoader to load it. I think it is not possible using proxy pattern.

Any ideas?

Angel C
  • 31
  • 4
  • How about showing the definition of the interface, the class you want to use, and how you're using it? – nasch Mar 24 '17 at 22:33
  • @nasch finally, I solved it. The method named "invoke" in the invocation handler of the proxy object receives a method like argument. If you want to use a class that doesn't implement the interface, you can't invoke this received method. I thought the problem was the ClassCastException, but I saw that when you are using a valid class that implements an interface, you receive this exception too (I don't know why). So you only have to redefine the invoke method, using the method of the class you want to use and invoke it, using the arguments you receive in the invoke method. – Angel C Mar 27 '17 at 07:54

0 Answers0