[英]passing a bluetoothSocket to another activity?
I am trying to send a bluetoothSocket to another activity, but since it isn't Parcelable
nor Serializable
I am kind of at a loss about what to do. 我正在尝试将bluetoothSocket发送到另一个活动,但是由于它既不可Parcelable
也不可Serializable
所以我对执行该操作感到有些Parcelable
。
I haven't found anything else on this though I've searched to find an example somewhere. 尽管我一直在寻找某个地方的示例,但我还没有找到其他任何东西。
Managing a BluetoothSocket
in an Activity
sounds like a bad idea as the BluetoothSocket
will be somewhat tied to the Activity
lifecycle. 在Activity
管理BluetoothSocket
听起来是个坏主意,因为BluetoothSocket
在某种程度上与Activity
生命周期相关。 You should consider moving the BluetoothSocket
to a Service
instead. 您应该考虑将BluetoothSocket
移至Service
。 The different activities that need to use the BluetoothSocket
can then do so through the Service
instance. 然后,可以通过Service
实例来执行需要使用BluetoothSocket
的各种活动。 You also get an extra benefit: your BluetoothSocket
can remain active even though your application is not in the foreground. 您还可以获得额外的好处:即使您的应用程序不在前台,您的BluetoothSocket
仍然可以保持活动状态。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.