1

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...

Divya Priya
  • 123
  • 1
  • 8

1 Answers1

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.

Community
  • 1
  • 1
Pradip
  • 3,189
  • 3
  • 22
  • 27