[Android] Prevent NPE when activity is missing

Geoffrey Métais git at videolan.org
Wed Apr 1 17:20:53 CEST 2015


vlc-ports/android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Wed Apr  1 17:20:10 2015 +0200| [c77a84ca181c8984dbdc47ab0fd6f7eb229f4eba] | committer: Geoffrey Métais

Prevent NPE when activity is missing

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

 .../src/org/videolan/vlc/gui/audio/AudioPlayer.java        |   12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
index a1aeaab..4762184 100644
--- a/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
+++ b/vlc-android/src/org/videolan/vlc/gui/audio/AudioPlayer.java
@@ -22,6 +22,7 @@ package org.videolan.vlc.gui.audio;
 
 import java.util.List;
 
+import android.app.Activity;
 import android.content.Context;
 import android.content.Intent;
 
@@ -619,10 +620,11 @@ public class AudioPlayer extends Fragment implements IAudioPlayer, View.OnClickL
             @Override
             public void run() {
                 if(!vibrated) {
-                    ((android.os.Vibrator) AudioPlayer.this.getActivity()
-                            .getSystemService(Context.VIBRATOR_SERVICE))
-                            .vibrate(80);
-                    ;
+                    Activity activity = AudioPlayer.this.getActivity();
+                    if (activity != null) {
+                        ((android.os.Vibrator) activity.getSystemService(Context.VIBRATOR_SERVICE))
+                                .vibrate(80);
+                    }
                     vibrated = true;
                 }
 
@@ -642,7 +644,9 @@ public class AudioPlayer extends Fragment implements IAudioPlayer, View.OnClickL
                 h.postDelayed(seekRunnable, 50);
             }
         };
+
         Handler h = new Handler();
+
         @Override
         public boolean onTouch(View v, MotionEvent event) {
             switch(event.getAction()) {



More information about the Android mailing list