android获取当前行所属类和所属方法名

 
 
第一种方法:
String Method = Thread.currentThread().getStackTrace()[2].getMethodName();
 
第二种方法:
private static final boolean FINAL_CONSTANT_IS_LOCAL = true;
private static final String TAG = FooProvider.class.getSimpleName();
 
private void String getLogTagWithMethod() {
    if (FINAL_CONSTANT_IS_LOCAL) {
        Throwable stack = new Throwable().fillInStackTrace();
        StackTraceElement[] trace = stack.getStatckTrace();
        return trace[0].getClassName() + "." + trace[0].getMethodName() + ":" + trace[0].getLineNumber();
    } else {
        return TAG;
    }
}

posted on 2016-02-01 17:30  On1Key  阅读(1386)  评论(0编辑  收藏  举报

导航