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...
3
-
do u want to show that in your logcat or toast?SathishKumar– SathishKumar2013-11-29 09:37:08 +00:00Commented Nov 29, 2013 at 9:37
-
I want to show method info in toast.Divya Priya– Divya Priya2013-11-29 09:38:53 +00:00Commented Nov 29, 2013 at 9:38
-
stackoverflow.com/questions/442747/… check this,SathishKumar– SathishKumar2013-11-29 09:48:10 +00:00Commented Nov 29, 2013 at 9:48
Add a comment
|
1 Answer
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.