Android 调试技巧之打印堆栈
用法一
Thread.dumpStack();
Note:
java.lang.Thread
/**
* Prints a stack trace of the current thread to the standard error stream.
* This method is used only for debugging.
*
* @see Throwable#printStackTrace()
*/
public static void dumpStack() {
new Exception("Stack trace").printStackTrace();
}
用法二
new Exception("关键字").printStackTrace();
用法三
android.os.Debug
Debug类里面有几个getCaller方法可以获得当前的StackTrace,在需要调试的方法法中直接调用即可
public void dumpStackTrace(){
android.os.Debug.getCallers(9);
}
Log.d(TAG,"log "+Debug.getCallers(9));