I have an Android app with a Java interface that has a single method, say void doStuff(String className). Others will provide me with .jar files, each containing a class that implements this interface, to be included in my APK. When doStuff() is called, I will receive as a parameter the name of the class that implements the interface. I would like to be able to then obtain an instance of that class and call doStuff() at run-time, without having any specific implementation class types defined in my own code. What is the best way to accomplish this?
I have an Android app with a Java interface that has a single method,
Share
You can do this with a mild amount of reflection:
This requires that the implementation classes have accessible no-args constructors.