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));

 

posted @   行走的思想  阅读(30)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
点击右上角即可分享
微信分享提示

目录导航