android调试之函数调用栈

理解函数调用栈,可以更好的阅读源码实现逻辑,而且在应用调试过程中追查bug具有积极作用。这里是基于阅读系统源码来讲的。

通常我是运用抛异常,然后看报错日志来追踪函数调用栈的,以Launcher3源码中拖拽开始函数为例:

    public void onDragStart(final DragSource source, Object info, int dragAction) {
        if(true){
			throw new RuntimeException("just test");
        }
        mIsDragOccuring = true;
        updateChildrenLayersEnabled(false);
        mLauncher.lockScreenOrientation();
        mLauncher.onInteractionBegin();
        setChildrenBackgroundAlphaMultipliers(1f);
        // Prevent any Un/InstallShortcutReceivers from updating the db while we are dragging
        InstallShortcutReceiver.enableInstallQueue();
        UninstallShortcutReceiver.enableUninstallQueue();
        post(new Runnable() {
            @Override
            public void run() {
                if (mIsDragOccuring) {
                    addExtraEmptyScreenOnDrag();
                }
            }
        });
    }

编译之后的apk重新导入运行,当拖拽app的时候就会报以下错误:
在这里插入图片描述
由此可知到拖拽开始的函数调用栈为:
Launcher.onLongClick() -> Workspace.startDrag -> Workspace.beginDragShared() ->DragController.startDrag() -> Workspace.onDragStart()

这里不仅仅知道了函数的调用栈,还可以确定具体报错的位置。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值