diff --git a/android/README.md b/android/README.md index fe2a30049..27eec01fd 100644 --- a/android/README.md +++ b/android/README.md @@ -56,6 +56,9 @@ public class MainActivity extends AppCompatActivity { protected void onDestroy() { super.onDestroy(); + view.dispose(); + view = null; + JitsiMeetView.onHostDestroy(this); } @@ -102,6 +105,12 @@ See JitsiMeetView.setWelcomePageEnabled. The `JitsiMeetView` class is the core of Jitsi Meet SDK. It's designed to display a Jitsi Meet conference (or a welcome page). +#### dispose() + +Releases all resources associated with this view. This method MUST be called +when the Activity holding this view is going to be destroyed, usually in the +`onDestroy()` method. + #### getListener() Returns the `JitsiMeetViewListener` instance attached to the view. diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivity.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivity.java index d24f796a2..87cf26a84 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivity.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivity.java @@ -154,6 +154,11 @@ public class JitsiMeetActivity extends AppCompatActivity { protected void onDestroy() { super.onDestroy(); + if (view != null) { + view.dispose(); + view = null; + } + JitsiMeetView.onHostDestroy(this); } diff --git a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java index b1a906d9e..35e262ffb 100644 --- a/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java +++ b/android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java @@ -199,6 +199,21 @@ public class JitsiMeetView extends FrameLayout { views.add(this); } + /** + * Releases the React resources (specifically the {@link ReactRootView}) + * associated with this view. + * + * This method MUST be called when the Activity holding this view is destroyed, typically in the + * {@code onDestroy} method. + */ + public void dispose() { + if (reactRootView != null) { + removeView(reactRootView); + reactRootView.unmountReactApplication(); + reactRootView = null; + } + } + /** * Gets the {@link JitsiMeetViewListener} set on this {@code JitsiMeetView}. * @@ -257,10 +272,7 @@ public class JitsiMeetView extends FrameLayout { // TODO: ReactRootView#setAppProperties is only available on React // Native 0.45, so destroy the current root view and create a new one. - if (reactRootView != null) { - removeView(reactRootView); - reactRootView = null; - } + dispose(); reactRootView = new ReactRootView(getContext()); reactRootView.startReactApplication(reactInstanceManager, "App", props);