NullPointerException on activity in onDismiss
Michal Szynkaruk [Wed, 10 Jun 2015 16:27:04 +0000 (18:27 +0200)]
Problem: getActivity() returns NULL after
the dialog fragment has been removed.
Solution: Add a null check for the activity
to which the dialogfragment is attached.

Change-Id: I32c8784b15b6f179d13071b508d6cd9d2013ebc3

ui/src/com/android/providers/downloads/ui/TrampolineActivity.java

index f96c04e..104f144 100644 (file)
@@ -152,7 +152,10 @@ public class TrampolineActivity extends Activity {
         @Override
         public void onDismiss(DialogInterface dialog) {
             super.onDismiss(dialog);
-            getActivity().finish();
+            final Activity activity = getActivity();
+            if (activity != null) {
+                activity.finish();
+            }
         }
     }
 
@@ -221,7 +224,10 @@ public class TrampolineActivity extends Activity {
         @Override
         public void onDismiss(DialogInterface dialog) {
             super.onDismiss(dialog);
-            getActivity().finish();
+            final Activity activity = getActivity();
+            if (activity != null) {
+                activity.finish();
+            }
         }
     }
 }