[Android] Avoid crash in Preferences

Jean-Baptiste Kempf git at videolan.org
Sun Jul 6 23:56:58 CEST 2014


vlc-ports/android | branch: master | Jean-Baptiste Kempf <jb at videolan.org> | Sun Jul  6 23:56:28 2014 +0200| [e7cd90f165ee8a8f3929ea60bbdd530a9f05cd6c] | committer: Jean-Baptiste Kempf

Avoid crash in Preferences

More checks and exception catching...

> http://git.videolan.org/gitweb.cgi/vlc-ports/android.git/?a=commit;h=e7cd90f165ee8a8f3929ea60bbdd530a9f05cd6c
---

 .../org/videolan/vlc/gui/PreferencesActivity.java  |   20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
index 7597182..2258baf 100644
--- a/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
+++ b/vlc-android/src/org/videolan/vlc/gui/PreferencesActivity.java
@@ -32,6 +32,7 @@ import org.videolan.vlc.util.BitmapCache;
 import org.videolan.vlc.util.Util;
 
 import android.app.AlertDialog;
+import android.app.Dialog;
 import android.content.Context;
 import android.content.DialogInterface;
 import android.content.Intent;
@@ -49,6 +50,7 @@ import android.preference.PreferenceActivity;
 import android.preference.PreferenceManager;
 import android.preference.PreferenceScreen;
 import android.text.format.DateFormat;
+import android.view.Window;
 import android.widget.Toast;
 
 @SuppressWarnings("deprecation")
@@ -296,12 +298,18 @@ public class PreferencesActivity extends PreferenceActivity implements OnSharedP
     public boolean onPreferenceTreeClick(PreferenceScreen preferenceScreen, Preference preference)
     {
         super.onPreferenceTreeClick(preferenceScreen, preference);
-        if (preference!=null)
-            if (preference instanceof PreferenceScreen)
-                if (((PreferenceScreen)preference).getDialog()!=null)
-                    ((PreferenceScreen)preference).getDialog().getWindow().getDecorView()
-                    .setBackgroundDrawable(this.getWindow().getDecorView().getBackground()
-                            .getConstantState().newDrawable());
+        try {
+            if (preference!=null && preference instanceof PreferenceScreen) {
+                Dialog dialog = ((PreferenceScreen)preference).getDialog();
+                if (dialog!=null) {
+                    Window window = dialog.getWindow();
+                    if(window != null)
+                        window.getDecorView().setBackgroundDrawable(
+                                this.getWindow().getDecorView().getBackground()
+                                .getConstantState().newDrawable());
+                }
+            }
+        } catch(Exception e){}
         return false;
     }
 



More information about the Android mailing list