我有以下代碼開始活動,代碼是當用戶點擊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