问题描述
我写的蓝牙客户端和我有一个问题。我的第一个活动启动显示ListView中的设备。在这个清单上的一些项目点击,它应该开始新的活动,并通过BluetoothDevice类对象那里。我写这样的事情:
I'm writing bluetooth client and I have a problem.My first activity display enabled devices in ListView. When click on some item on this list, it should start new activity and pass a BluetoothDevice object there. I write something like that:
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
// TODO Auto-generated method stub
if(btAdapter.isDiscovering()) {
btAdapter.cancelDiscovery();
}
if(listAdapter.getItem(position).contains("Paired")) {
BluetoothDevice selectedDevice = devices.get(position);
Intent intent = new Intent (this, BTActivity.class);
intent.putExtra("btdevice", selectedDevice);
startActivity(intent);
是否有可能通过BluetoothDevice类对象到另一个活动?如何提取该对象在新的活动?
Is it possible to pass BluetoothDevice object to another activity? How to extract this object in new activity?
对不起,我的英语。如果事情是不明确的,我会尝试更好地解释。
Sorry for my English. If something isn't clear, I will try explain better.
推荐答案
是的。这是可能的,因为 BluetoothDevice类
类工具
Parcelable
Yes . It is possible since BluetoothDevice
class implements
Parcelable
您可以在其他活动对象
像这样
BluetoothDevice bluetoothDevice = getIntent().getExtras().getParcelable("btdevice");
确认getIntent()。getExtras()不为空
Make sure getIntent().getExtras() is not null
这篇关于通过BluetoothDevice类对象到另一个活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!