项目中是通过这种方式打印函数调用栈:
Log.e(TAG, Log.getStackTraceString(new Throwable()));
打印效果如下:
05-10 15:31:19.754 19991-19991/com.meizu.media.camera E/huannan: java.lang.Throwable
at com.meizu.media.camera...(....java:403)
at com.meizu.media.camera....(....java:248)
at com.meizu.media.camera....(....java:4649)
at com.meizu.media.camera....(....java:1307)
at com.meizu.media.camera....(....java:98)
at com.meizu.media.camera....(....java:1573)
at android.os.Handler.dispatchMessage(Handler.java:110)
at android.os.Looper.loop(Looper.java:203)
at android.app.ActivityThread.main(ActivityThread.java:6476)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1113)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:974)
优点:这个方法在项目比较复杂,尤其是调用链关系比较复杂的时候很好用
缺点:打印函数调用栈可能会影响性能,因此最好在测试Debug中使用
网友评论