Pregunta

Is it possible to change at runtime the behaviour of a method from a class already loaded using Dexmaker, by proxing or generating code?

UPDATE

Just a remark: I want to add a method/modify existing one from my own application, not from the android framework.

¿Fue útil?

Solución

No. It is not possible.

You could create a new class that extends the original, or possibly even make a copy of the class, with a new name and a tweaked implementation. But you can't replace an existing class.

Your best bet is probably to extract out the code that you might want to modify into a separate class, and then pass in an instance of that class to whatever uses it. And then, if you need to create a new implementation, you can subclass it and pass in the subclass instead.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top