我想将“BluetoothDevice”类的对象从 Activity 传递到服务。我正在获取传递字符串或任何原始类型但不传递对象的语法。请帮忙。提前致谢。
最佳答案
您应该创建一个包含要传递的数据的类,并从 Serialized
或 Parcelable
扩展该类,然后您可以将该类的对象作为 Extra
到您的Intent
并在您的Service
编辑:
正如 rom4ek 提到的,BluetoothDevice
已经实现了 Parcelable
,您所要做的就是:
Bundle b = new Bundle();
b.putParcelable("data", yourBluetoothDeviceObject);
yourIntent.putExtra(b);
以及检索数据:
Bundle b = yourIntent.getExtra();
BluetoothDevice device = (BluetoothDevice) b.getParcelable("data");
关于android - 如何将任何对象从 Activity 传递到服务?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27309125/