开发者

In Android, how do I find caller of a method efficiently

开发者 https://www.devze.com 2023-04-03 17:23 出处:网络
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开发

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?


There's Thread.getStackTrace().

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号