获取当前正在执行的方法的名称
嗯,我基本上做的是一个有很多活动的应用程序。我有几个使用 Android 手机的朋友,我给他们提供了该应用程序进行测试。然而,它有时会进入无限循环并做出奇怪的行为,由于他们缺乏编程经验并且无法在那些特定时刻转储 logcat,所以我无法理解这些行为。
所以我需要做的是创建一个静态的始终可见的窗口,可能是弹出窗口,显示程序现在在哪个方法中。
所以我的问题是,这是实现此功能的最佳方法以及如何检索应用程序所在的当前方法(它有多个线程)。
Well what I am basically doing is an app which has many activities. I have a few friends with android phones and I gave them the app for testing. However, it sometimes goes into endless cycles and does strange behaviour which I am not able to understand due to their lack of programming experience and inability to dump the logcat in those particular moments.
So what I need to do is to create a static always visible window, probably popup window, that shows in which method is the program now.
So my question would be, which is the best way to achieve this functionality and how to retrieve the current method the App is in (it has several threads).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在我的设备上它是 -
Thread.currentThread().getStackTrace()[2].getMethodName()
(不是 [1] 而是 [2])
On my device it's -
Thread.currentThread().getStackTrace()[2].getMethodName()
(not [1] but [2])
你可以试试这个:
它会返回类似这样的内容:
ClassName.methodName():123
You can try this:
It will return something like this:
ClassName.methodName():123
如果你搜索的话,会有很多答案。这是一个简单的方法,
您应该参考这篇文章。
获取当前执行方法的名称
There are many answers for this if you search SO. This is a simple method
You should refer this post.
Getting the name of the current executing method