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:
Jiehua.Dai
2010-05-12 08:37:52 +02:00
committed by Johan Redestig
parent 05c2b96f42
commit 20108e2ed6
6 changed files with 208 additions and 79 deletions

View File

@@ -18,6 +18,7 @@ package com.android.settings;
import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.ContentResolver;
import android.content.Intent;
import android.net.Proxy;
@@ -73,6 +74,7 @@ public class ProxySelector extends Activity
HOSTNAME_PATTERN = Pattern.compile(HOSTNAME_REGEXP);
}
private static final int ERROR_DIALOG_ID = 0;
public void onCreate(Bundle icicle) {
super.onCreate(icicle);
@@ -84,13 +86,32 @@ public class ProxySelector extends Activity
populateFields(false);
}
protected void showError(int error) {
@Override
protected Dialog onCreateDialog(int id) {
if (id == ERROR_DIALOG_ID) {
String hostname = mHostnameField.getText().toString().trim();
String portStr = mPortField.getText().toString().trim();
String msg = getString(validate(hostname, portStr));
new AlertDialog.Builder(this)
.setTitle(R.string.proxy_error)
.setMessage(error)
.setPositiveButton(R.string.proxy_error_dismiss, null)
.show();
return new AlertDialog.Builder(this)
.setTitle(R.string.proxy_error)
.setPositiveButton(R.string.proxy_error_dismiss, null)
.setMessage(msg)
.create();
}
return super.onCreateDialog(id);
}
@Override
protected void onPrepareDialog(int id, Dialog dialog) {
super.onPrepareDialog(id, dialog);
if (id == ERROR_DIALOG_ID) {
String hostname = mHostnameField.getText().toString().trim();
String portStr = mPortField.getText().toString().trim();
String msg = getString(validate(hostname, portStr));
((AlertDialog)dialog).setMessage(msg);
}
}
void initView() {
@@ -188,7 +209,7 @@ public class ProxySelector extends Activity
int result = validate(hostname, portStr);
if (result > 0) {
showError(result);
showDialog(ERROR_DIALOG_ID);
return false;
}