diff --git a/src/com/android/settings/bluetooth/BluetoothSettings.java b/src/com/android/settings/bluetooth/BluetoothSettings.java index 1282409a832..826a451022a 100755 --- a/src/com/android/settings/bluetooth/BluetoothSettings.java +++ b/src/com/android/settings/bluetooth/BluetoothSettings.java @@ -392,7 +392,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem final CachedBluetoothDevice device = (CachedBluetoothDevice) v.getTag(); final Activity activity = getActivity(); - DeviceProfilesSettings profileFrag = (DeviceProfilesSettings)activity. + DeviceProfilesSettings profileFragment = (DeviceProfilesSettings)activity. getFragmentManager().findFragmentById(R.id.bluetooth_fragment_settings); if (mSettingsDialogView != null){ @@ -402,23 +402,26 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem } } - if (profileFrag == null) { + if (profileFragment == null) { LayoutInflater inflater = getActivity().getLayoutInflater(); mSettingsDialogView = inflater.inflate(R.layout.bluetooth_device_settings, null); - profileFrag = (DeviceProfilesSettings)activity.getFragmentManager() + profileFragment = (DeviceProfilesSettings)activity.getFragmentManager() .findFragmentById(R.id.bluetooth_fragment_settings); // To enable scrolling we store the name field in a seperate header and add to - // the ListView of the profileFrag. + // the ListView of the profileFragment. View header = inflater.inflate(R.layout.bluetooth_device_settings_header, null); - profileFrag.getListView().addHeaderView(header); + profileFragment.getListView().addHeaderView(header); } final View dialogLayout = mSettingsDialogView; AlertDialog.Builder settingsDialog = new AlertDialog.Builder(activity); - profileFrag.setDevice(device); + profileFragment.setDevice(device); final EditText deviceName = (EditText)dialogLayout.findViewById(R.id.name); deviceName.setText(device.getName(), TextView.BufferType.EDITABLE); + + final DeviceProfilesSettings dpsFragment = profileFragment; + final Context context = v.getContext(); settingsDialog.setView(dialogLayout); settingsDialog.setTitle(R.string.bluetooth_preference_paired_devices); settingsDialog.setPositiveButton(R.string.okay, @@ -429,7 +432,7 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem device.setName(deviceName.getText().toString()); } }); - final Context context = v.getContext(); + settingsDialog.setNegativeButton(R.string.forget, new DialogInterface.OnClickListener() { @Override @@ -442,6 +445,16 @@ public final class BluetoothSettings extends DeviceListPreferenceFragment implem } }); + // We must ensure that the fragment gets destroyed to avoid duplicate fragments. + settingsDialog.setOnDismissListener(new DialogInterface.OnDismissListener() { + public void onDismiss(final DialogInterface dialog) { + if (!activity.isDestroyed()) { + activity.getFragmentManager().beginTransaction().remove(dpsFragment) + .commitAllowingStateLoss(); + } + } + }); + AlertDialog dialog = settingsDialog.create(); dialog.create(); dialog.show(); diff --git a/src/com/android/settings/bluetooth/DeviceProfilesSettings.java b/src/com/android/settings/bluetooth/DeviceProfilesSettings.java index ee25300da9f..5c2beba38cc 100755 --- a/src/com/android/settings/bluetooth/DeviceProfilesSettings.java +++ b/src/com/android/settings/bluetooth/DeviceProfilesSettings.java @@ -232,7 +232,7 @@ public final class DeviceProfilesSettings extends SettingsPreferenceFragment status == BluetoothProfile.STATE_CONNECTED; if (isConnected) { - askDisconnect(getActivity(), profile); + askDisconnect(mManager.getForegroundActivity(), profile); } else { if (profile.isPreferred(device)) { // profile is preferred but not connected: disable auto-connect