[Android] Prevent NPE in browsers

Geoffrey Métais git at videolan.org
Thu Sep 21 12:03:48 CEST 2017


vlc-android | branch: master | Geoffrey Métais <geoffrey.metais at gmail.com> | Thu Sep 21 11:38:28 2017 +0200| [3fc04ca4aa997e60a977b2573ca107a047b1c077] | committer: Geoffrey Métais

Prevent NPE in browsers

> https://code.videolan.org/videolan/vlc-android/commit/3fc04ca4aa997e60a977b2573ca107a047b1c077
---

 .../src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java     | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
index 2e47d91a1..1d9ec5e58 100644
--- a/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
+++ b/vlc-android/src/org/videolan/vlc/gui/browser/BaseBrowserFragment.java
@@ -23,7 +23,6 @@
 package org.videolan.vlc.gui.browser;
 
 import android.annotation.TargetApi;
-import android.app.Activity;
 import android.content.Intent;
 import android.net.Uri;
 import android.os.Build;
@@ -35,6 +34,7 @@ import android.os.Process;
 import android.support.annotation.NonNull;
 import android.support.annotation.Nullable;
 import android.support.v4.app.Fragment;
+import android.support.v4.app.FragmentActivity;
 import android.support.v4.app.FragmentManager;
 import android.support.v4.app.FragmentTransaction;
 import android.support.v4.util.SimpleArrayMap;
@@ -271,9 +271,11 @@ public abstract class BaseBrowserFragment extends SortableFragment<BaseBrowserAd
     }
 
     public void goBack(){
-        Activity activity = getActivity();
+        final FragmentActivity activity = getActivity();
+        if (activity == null)
+            return;
         if (!mRoot) {
-            if (!getActivity().getSupportFragmentManager().popBackStackImmediate() && activity instanceof MainActivity)
+            if (!activity.getSupportFragmentManager().popBackStackImmediate() && activity instanceof MainActivity)
                 ((MainActivity)activity).showFragment(this instanceof NetworkBrowserFragment ? R.id.nav_network : R.id.nav_directories);
         } else
             activity.finish();



More information about the Android mailing list