Fix a dialog leak. #1792635
Fixes the dialog leak when switching orientation in Development settings.
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package com.android.settings;
|
||||
|
||||
import android.app.AlertDialog;
|
||||
import android.app.Dialog;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.BatteryManager;
|
||||
import android.os.Bundle;
|
||||
@@ -45,6 +46,8 @@ public class DevelopmentSettings extends PreferenceActivity
|
||||
// To track whether Yes was clicked in the adb warning dialog
|
||||
private boolean mOkClicked;
|
||||
|
||||
private Dialog mOkDialog;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle icicle) {
|
||||
super.onCreate(icicle);
|
||||
@@ -80,14 +83,15 @@ public class DevelopmentSettings extends PreferenceActivity
|
||||
if (preference == mEnableAdb) {
|
||||
if (mEnableAdb.isChecked()) {
|
||||
mOkClicked = false;
|
||||
new AlertDialog.Builder(this).setMessage(
|
||||
if (mOkDialog != null) dismissDialog();
|
||||
mOkDialog = new AlertDialog.Builder(this).setMessage(
|
||||
getResources().getString(R.string.adb_warning_message))
|
||||
.setTitle(R.string.adb_warning_title)
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setPositiveButton(android.R.string.yes, this)
|
||||
.setNegativeButton(android.R.string.no, this)
|
||||
.show()
|
||||
.setOnDismissListener(this);
|
||||
.show();
|
||||
mOkDialog.setOnDismissListener(this);
|
||||
} else {
|
||||
Settings.Secure.putInt(getContentResolver(), Settings.Secure.ADB_ENABLED, 0);
|
||||
}
|
||||
@@ -99,10 +103,15 @@ public class DevelopmentSettings extends PreferenceActivity
|
||||
Settings.Secure.putInt(getContentResolver(), Settings.Secure.ALLOW_MOCK_LOCATION,
|
||||
mAllowMockLocation.isChecked() ? 1 : 0);
|
||||
}
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void dismissDialog() {
|
||||
mOkDialog.dismiss();
|
||||
mOkDialog = null;
|
||||
}
|
||||
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
if (which == DialogInterface.BUTTON_POSITIVE) {
|
||||
mOkClicked = true;
|
||||
@@ -119,4 +128,10 @@ public class DevelopmentSettings extends PreferenceActivity
|
||||
mEnableAdb.setChecked(false);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
dismissDialog();
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user