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
diff --git a/src/com/android/settings/SettingsSafetyLegalActivity.java b/src/com/android/settings/SettingsSafetyLegalActivity.java
index 0c51928..368ee1d 100644
--- a/src/com/android/settings/SettingsSafetyLegalActivity.java
+++ b/src/com/android/settings/SettingsSafetyLegalActivity.java
@@ -40,6 +40,8 @@
private WebView mWebView;
+ private AlertDialog mErrorDialog = null;
+
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
@@ -85,14 +87,31 @@
}
private void showErrorAndFinish(String url) {
- new AlertDialog.Builder(this)
- .setMessage(getResources()
- .getString(R.string.settings_safetylegal_activity_unreachable, url))
- .setTitle(R.string.settings_safetylegal_activity_title)
- .setPositiveButton(android.R.string.ok, this)
- .setOnCancelListener(this)
- .setCancelable(true)
- .show();
+ if (mErrorDialog == null) {
+ mErrorDialog = new AlertDialog.Builder(this)
+ .setTitle(R.string.settings_safetylegal_activity_title)
+ .setPositiveButton(android.R.string.ok, this)
+ .setOnCancelListener(this)
+ .setCancelable(true)
+ .create();
+ } else {
+ if (mErrorDialog.isShowing()) {
+ mErrorDialog.dismiss();
+ }
+ }
+ mErrorDialog.setMessage(getResources()
+ .getString(R.string.settings_safetylegal_activity_unreachable, url));
+ mErrorDialog.show();
+ }
+
+ @Override
+ protected void onDestroy() {
+ super.onDestroy();
+
+ if (mErrorDialog != null) {
+ mErrorDialog.dismiss();
+ mErrorDialog = null;
+ }
}
@Override