Question

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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top