【发布时间】:2013-12-17 19:37:26
【问题描述】:
我需要在android中获取调用方法名称和行号,我试过了
Thread.currentThread().getStackTrace()[2].getMethodName())
但这会给出调用方法名称,但我需要打印调用方法名称,谁能帮我解决这个问题。
【问题讨论】:
标签: android
我需要在android中获取调用方法名称和行号,我试过了
Thread.currentThread().getStackTrace()[2].getMethodName())
但这会给出调用方法名称,但我需要打印调用方法名称,谁能帮我解决这个问题。
【问题讨论】:
标签: android
类名
this.getClass().getName();
行号
Thread.currentThread().getStackTrace()[1].getLineNumber();
方法是
Thread.currentThread().getStackTrace()[1].getMethodName();
从getStackTrace() 访问数组中的正确元素。
【讨论】:
试试这样的:
method2(){
method1("method2");
}
method3(){
method1("method3");
}
method1(String Callingname){
Log.d("Method1", "Callingname")
}
【讨论】: