I need to display the calling methods details like line number, method name and class name. How to get all those information in android,whenever a method is called in an application the calling method info has to be dispalyed,can anyone help me in solving this...
Asked
Active
Viewed 430 times
1
-
do u want to show that in your logcat or toast? – SathishKumar Nov 29 '13 at 09:37
-
I want to show method info in toast. – Divya Priya Nov 29 '13 at 09:38
-
http://stackoverflow.com/questions/442747/getting-the-name-of-the-current-executing-method check this, – SathishKumar Nov 29 '13 at 09:48
1 Answers
1
You can get using the following code- [copied from How to get method name for debug output in Android/Java? ]
Thread current = Thread.currentThread();
StackTraceElement[] stack = current.getStackTrace();
for(StackTraceElement element : stack)
{
if (!element.isNativeMethod()) {
String className = element.getClassName();
String fileName = element.getFileName();
int lineNumber = element.getLineNumber();
String methodName = element.getMethodName();
}
}
Once you got the line number, method name, class name you can use it as you wish.