通过Intent传递对象

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接口方法。

原文地址:https://www.cnblogs.com/fengzhblog/p/3188063.html