我有以下代码开始活动,代码是当用户点击Android设备上的菜单按钮时出现的子菜单,它的问题是,当按钮被点击一个新的活动开始了,这会丢失之前形成的蓝牙连接!新的活动开始于意图
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent serverIntent = null;
Intent PassIntent;
Intent PassIntent1;
switch (item.getItemId()) {
/*case R.id.home:
// Launch the DeviceListActivity to see devices and do scan
serverIntent = new Intent(this, engineStarter.class);
startActivity(serverIntent);
return true;*/
/*case R.id.insecure_connect_scan:
// Launch the DeviceListActivity to see devices and do scan
serverIntent = new Intent(this, DeviceListActivity.class);
startActivityForResult(serverIntent, REQUEST_CONNECT_DEVICE_INSECURE);
return true;*/
/*case R.id.discoverable:
// Ensure this device is discoverable by others
ensureDiscoverable();
return true;*/
case R.id.setpassword:
PassIntent = new Intent(this, SetPassword.class);
startActivity(PassIntent);
return true;
case R.id.home:
// Launch the DeviceListActivity to see devices and do scan
serverIntent = new Intent(this, engineStarter.class);
startActivity(serverIntent);
return true;
}
return false;
}
我真正想要的只是加载活动与以前的状态,而不是再次创建活动性和松散的连接! – Naaz 2013-02-17 20:02:38
为什么不通过服务来管理蓝牙连接? – 2013-02-17 20:38:22
我试过了,但我记得我被卡在某个地方,所以只是没有这样去! – Naaz 2013-02-17 21:05:55