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

3
  • do u want to show that in your logcat or toast? Commented Nov 29, 2013 at 9:37
  • I want to show method info in toast. Commented Nov 29, 2013 at 9:38
  • stackoverflow.com/questions/442747/… check this, Commented Nov 29, 2013 at 9:48

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.