Fix a dialog leak. #1792635

Fixes the dialog leak when switching orientation in Development
settings.
This commit is contained in:
Amith Yamasani
2009-08-12 05:42:23 -07:00
parent 443c8e3177
commit 24bd892bde

View File

@@ -17,6 +17,7 @@
package com.android.settings; package com.android.settings;
import android.app.AlertDialog; import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface; import android.content.DialogInterface;
import android.os.BatteryManager; import android.os.BatteryManager;
import android.os.Bundle; import android.os.Bundle;
@@ -45,6 +46,8 @@ public class DevelopmentSettings extends PreferenceActivity
// To track whether Yes was clicked in the adb warning dialog // To track whether Yes was clicked in the adb warning dialog
private boolean mOkClicked; private boolean mOkClicked;
private Dialog mOkDialog;
@Override @Override
protected void onCreate(Bundle icicle) { protected void onCreate(Bundle icicle) {
super.onCreate(icicle); super.onCreate(icicle);
@@ -80,14 +83,15 @@ public class DevelopmentSettings extends PreferenceActivity
if (preference == mEnableAdb) { if (preference == mEnableAdb) {
if (mEnableAdb.isChecked()) { if (mEnableAdb.isChecked()) {
mOkClicked = false; mOkClicked = false;
new AlertDialog.Builder(this).setMessage( if (mOkDialog != null) dismissDialog();
mOkDialog = new AlertDialog.Builder(this).setMessage(
getResources().getString(R.string.adb_warning_message)) getResources().getString(R.string.adb_warning_message))
.setTitle(R.string.adb_warning_title) .setTitle(R.string.adb_warning_title)
.setIcon(android.R.drawable.ic_dialog_alert) .setIcon(android.R.drawable.ic_dialog_alert)
.setPositiveButton(android.R.string.yes, this) .setPositiveButton(android.R.string.yes, this)
.setNegativeButton(android.R.string.no, this) .setNegativeButton(android.R.string.no, this)
.show() .show();
.setOnDismissListener(this); mOkDialog.setOnDismissListener(this);
} else { } else {
Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 0); Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 0);
} }
@@ -103,6 +107,11 @@ public class DevelopmentSettings extends PreferenceActivity
return false; return false;
} }
private void dismissDialog() {
mOkDialog.dismiss();
mOkDialog = null;
}
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
if (which == DialogInterface.BUTTON_POSITIVE) { if (which == DialogInterface.BUTTON_POSITIVE) {
mOkClicked = true; mOkClicked = true;
@@ -119,4 +128,10 @@ public class DevelopmentSettings extends PreferenceActivity
mEnableAdb.setChecked(false); mEnableAdb.setChecked(false);
} }
} }
@Override
public void onDestroy() {
dismissDialog();
super.onDestroy();
}
} }