【问题标题】:Android Studio debug invoked methodAndroid Studio 调试调用方法
【发布时间】:2021-05-16 09:42:42
【问题描述】:

有没有办法调试被调用的方法?

我正在调用这个方法,但没有抛出任何错误。

Class Reference:
方法:public boolean disconnect(BluetoothDevice device)

发送的结果是false。出于这个原因,这些行中的任何一个都必须已执行并分配了布尔值。我希望service.disconnect(device) 被调用并返回false,但我想证明这一点。

try {
   [...]
   if (service != null && isEnabled() && isValidDevice(device)) {
      return service.disconnect(device);
   }
   if (service == null) Log.w(TAG, "Proxy not attached to service");
   return false;
} catch (RemoteException e) {
   Log.e(TAG, "Stack:" + Log.getStackTraceString(new Throwable()));
   return false;
}

BluetoothA2dp.disconnect() 被这段代码调用

private fun disconnect(context: Context, device: BluetoothDevice) {
  val serviceListener: ServiceListener = object : ServiceListener {
    override fun onServiceConnected(profile: Int, proxy: BluetoothProfile) {
      try {
        val disconnectMethod = BluetoothA2dp::class.java.getDeclaredMethod("disconnect", BluetoothDevice::class.java)
        disconnectMethod.isAccessible = true
        val cReturn = disconnectMethod.invoke(proxy, device) as Boolean
        } catch (ex: Throwable) {
          error("disconnectMethod", ex)
        } finally {
          bluetoothAdapter!!.closeProfileProxy(profile, proxy)
        }
      }
      override fun onServiceDisconnected(profile: Int) {}
    }
  bluetoothAdapter!!.getProfileProxy(context, serviceListener, BluetoothProfile.A2DP)
}
法布里奇奥的方式:

遗憾的是,叠加层被隐藏了,但我点击了step in

Youtube-Video

【问题讨论】:

    标签: java android android-studio kotlin


    【解决方案1】:

    在调试时,您有一些控件可以跳转到方法调用。 您可以通过转到“运行 -> 调试操作”来查看它们。

    你可以在你的方法调用上设置一个断点,这样当你运行调试时它会停在那里,然后你可以按 F7 跳转到方法调用,看看里面发生了什么:

    【讨论】:

    • 是的,这是基本的调试,但是你如何调试一个被调用的方法
    • 请看提供的视频
    • 嗨@GreilOmatics 看来你必须清理构建和重建
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-17
    • 2021-06-03
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 2013-05-11
    相关资源
    最近更新 更多