Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/184.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 将Bluetooth对象传递给新活动_Android_Bluetooth - Fatal编程技术网

Android 将Bluetooth对象传递给新活动

Android 将Bluetooth对象传递给新活动,android,bluetooth,Android,Bluetooth,我愿意制作一个应用程序,通过蓝牙发送数据。我有一个连接到蓝牙设备的主要活动,我可以将数据写入连接的设备。它工作得很好。我使用本回购协议的代码示例: 我通过以下命令创建蓝牙服务“对象”: mChatService = new BluetoothChatService(getActivity(), mHandler); 我可以通过以下方式发送数据: byte[] send = message.getBytes(); mChatService.write(send); 问题是,现在,我想在我的智

我愿意制作一个应用程序,通过蓝牙发送数据。我有一个连接到蓝牙设备的主要活动,我可以将数据写入连接的设备。它工作得很好。我使用本回购协议的代码示例:

我通过以下命令创建蓝牙服务“对象”:

mChatService = new BluetoothChatService(getActivity(), mHandler);
我可以通过以下方式发送数据:

byte[] send = message.getBytes();
mChatService.write(send);
问题是,现在,我想在我的智能手机连接到蓝牙设备后启动一个新的活动,我想传递蓝牙聊天对象,以便该活动可以获取该对象,然后依次向蓝牙设备写入,如下所示:

Intent newActivity = new Intent(MainActivity.this, SecondActivity.class);
newActivity.putExtra("BluetoothDevice", mChatService);
startActivity(JoystickActivity);
但是很明显,这不可能像那样传递我的蓝牙对象。我试图查看可序列化类型,但没有成功地使某些东西起作用

有人知道如何将这个“BluetoothChatService”对象传递给新活动吗?或者,有没有其他方法,比如让所有活动都可以访问它