BluetoothDevice device = data.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

在蓝牙开发中,通过intent(data)传递BluetoothDevice对象,先后调用putParcelableExtra和getParcelableExtra存入和取出BluetoothDevice对象。

put/getParcelableExtra方法操作的对象必须是实现Parcelable接口。

查看BluetoothDevice源码,它确实实现了接口Parcelable以及实现其接口方法

public final class BluetoothDevice implements Parcelable

public void writeToParcel(Parcel out, int flags) {
    out.writeString(mAddress);
}

 

在本项目中传递TxrjContact对象,也要使TxrjContact实现Parcelable接口及其writeToParcel接口方法。

相关文章:

  • 2021-07-03
  • 2022-03-03
  • 2022-01-11
  • 2021-08-17
  • 2022-12-23
  • 2021-09-21
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-08
  • 2021-06-01
  • 2021-12-28
相关资源
相似解决方案