Fix window leak problems in settings.
There were window leak in the settings application. These leak happens when an AlertDialog displays, rotate the phone, then it would cause window leak. Change-Id: I914897bf657933efea72eeea66076dc288098420
This commit is contained in:
committed by
Johan Redestig
parent
05c2b96f42
commit
20108e2ed6
@@ -55,6 +55,8 @@ public class LanguageSettings extends PreferenceActivity {
|
||||
|
||||
private String mLastInputMethodId;
|
||||
private String mLastTickedInputMethodId;
|
||||
|
||||
private AlertDialog mDialog = null;
|
||||
|
||||
static public String getInputMethodIdFromKey(String key) {
|
||||
return key;
|
||||
@@ -255,29 +257,35 @@ public class LanguageSettings extends PreferenceActivity {
|
||||
if (selImi == null) {
|
||||
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
||||
}
|
||||
AlertDialog d = (new AlertDialog.Builder(this))
|
||||
.setTitle(android.R.string.dialog_alert_title)
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setMessage(getString(R.string.ime_security_warning,
|
||||
selImi.getServiceInfo().applicationInfo.loadLabel(
|
||||
getPackageManager())))
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(android.R.string.ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
chkPref.setChecked(true);
|
||||
mLastTickedInputMethodId = id;
|
||||
}
|
||||
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
}
|
||||
|
||||
})
|
||||
.create();
|
||||
d.show();
|
||||
if (mDialog == null) {
|
||||
mDialog = (new AlertDialog.Builder(this))
|
||||
.setTitle(android.R.string.dialog_alert_title)
|
||||
.setIcon(android.R.drawable.ic_dialog_alert)
|
||||
.setCancelable(true)
|
||||
.setPositiveButton(android.R.string.ok,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
chkPref.setChecked(true);
|
||||
mLastTickedInputMethodId = id;
|
||||
}
|
||||
|
||||
})
|
||||
.setNegativeButton(android.R.string.cancel,
|
||||
new DialogInterface.OnClickListener() {
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
}
|
||||
|
||||
})
|
||||
.create();
|
||||
} else {
|
||||
if (mDialog.isShowing()) {
|
||||
mDialog.dismiss();
|
||||
}
|
||||
}
|
||||
mDialog.setMessage(getString(R.string.ime_security_warning,
|
||||
selImi.getServiceInfo().applicationInfo.loadLabel(
|
||||
getPackageManager())));
|
||||
mDialog.show();
|
||||
} else if (id.equals(mLastTickedInputMethodId)) {
|
||||
mLastTickedInputMethodId = null;
|
||||
}
|
||||
@@ -302,4 +310,13 @@ public class LanguageSettings extends PreferenceActivity {
|
||||
return super.onPreferenceTreeClick(preferenceScreen, preference);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mDialog != null) {
|
||||
mDialog.dismiss();
|
||||
mDialog = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user