From 63a92db540820f6abd84c189b561ef35781a9043 Mon Sep 17 00:00:00 2001 From: EricKuck Date: Tue, 5 Jul 2022 10:43:06 -0500 Subject: [PATCH] Pass along View's context on destroy if available --- .../com/bluelinelabs/conductor/Controller.java | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/conductor/src/main/java/com/bluelinelabs/conductor/Controller.java b/conductor/src/main/java/com/bluelinelabs/conductor/Controller.java index 83704b6..7230132 100644 --- a/conductor/src/main/java/com/bluelinelabs/conductor/Controller.java +++ b/conductor/src/main/java/com/bluelinelabs/conductor/Controller.java @@ -1035,7 +1035,11 @@ public abstract class Controller { } private void removeViewReference() { + Context context = null; + if (view != null) { + context = view.getContext(); + if (!isBeingDestroyed && !hasSavedViewState) { saveViewState(view); } @@ -1071,7 +1075,7 @@ public abstract class Controller { } if (isBeingDestroyed) { - performDestroy(); + performDestroy(context); } } @@ -1148,9 +1152,13 @@ public abstract class Controller { } } - private void performDestroy() { + private void performDestroy(@Nullable Context context) { + if (context == null) { + context = getActivity(); + } + if (isContextAvailable) { - onContextUnavailable(getActivity()); + onContextUnavailable(context); } if (!destroyed) {