Get the name of the currently executing method

Well, what I mostly do is an application that has a lot of action. I have some friends with Android phones and I gave them an app for testing. However, it sometimes goes into endless cycles and makes strange behavior that I cannot understand due to the lack of programming experience and the inability to reset the logarithm at these moments.

So what I need to do is create a static always visible window, possibly a popup that shows which method the program is in.

So my question will be, this is the best way to achieve this functionality and how to get the current method in which the application is located (it has several threads).

+7
source share
4 answers
Thread.currentThread().getStackTrace()[1].getMethodName() 
+7
source

You can try the following:

 public String getCurrentMethod(){ try{ throw new Exception(""); }catch(Exception e){ return e.getStackTrace()[0].toString(); } return ""; // This never happens } 

It will return something like this:
ClassName.methodName():123

+7
source

There are many answers for this if you are looking for SO. This is a simple method.

 String name = new Object(){}.getClass().getEnclosingMethod().getName(); 

You should direct this post. Getting the name of the current execution method

+6
source

On my device, this is Thread.currentThread().getStackTrace()[2].getMethodName()

(not [1] but [2])

+2
source

All Articles