Follow my comments above:
do this to call com.blah.MyActivity::myFunction :
com.blah.MyActivity activity = new com.blah.MyActivity() ; method = Class.forName("com.blah.MyActivity").getMethod('myFunction',String.class); method.invoke (activity, stringValue);
(forgive C ++ syntax)
I will try to explain why it works as follows:
A method is just a special type of function. This is a convenience created for people to deal with classes and objects.
As you know, inside the method you always have the this variable .. behind these scenes, this is passed as a parameter, but the following is written instead:
com.blah.MyActivity activity = new com.blah.MyActivity() ; com.blah.MyActivity::myFunction( activity, stringValue )
you can easily write this:
com.blah.MyActivity activity = new com.blah.MyActivity() ; activity.myFunction(stringValue)
When you get a method using reflection, it's just a "normal function". To call it directly, you need to pass the this parameter.
That's why you have errors like ... myFunction expects the first hidden argument to be an instance of it, containing the class you skipped.
NTN
source share