I am building a testing/analysis tool that requires instrumentation of Android framework classes. In that tool, the classes need to be instrumented to find out the caller of a method (i.e., method signature) that is currently being executed, and based on the caller some processing is done. My question is, which method I should use to determine the caller?
I know that one approach is to use java.lang.Throwable and the method getStackTrace. However, it is not efficient. Are there any other (public or hidden) API's (similar to sun.reflect.Reflection.getCallerClass of standard JDK) for Android platform that can be used?
Sometimes it is nice to access the caller of a method. Doing this is relatively simple, you can use the getStackTrace() method on the current thread.
Method Calls A method is a routine that applies to a particular class of objects. Once an object is declared, you can refer to it by its identifier when calling methods. The following example calls the SetActive method on the Find dialog box: Find.SetActive ()
Write the callAll() method to actually call each method explicitly without reflection. This allows for flexibility in subclassing. It also allows you to deal with methods which have parameters. It also allows you to bypass methods which don't apply.
There's Thread.getStackTrace().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With