[Android] Fix resource leak when JitsiMeetView is destroyed

In iOS this is automagically done in the view destructor, bunt we don't have
that luxury in Java we have to do it manually.

The new disponse() method MUST be called when the Activity holding the view is
going to be destroyed, typically in the onDestroy() handler.
This commit is contained in:
Saúl Ibarra Corretgé 2017-07-26 16:41:27 +02:00 committed by Любомир Маринов
parent 03b043ca2b
commit bfa5f4c953
3 changed files with 30 additions and 4 deletions

View File

@ -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.

View File

@ -154,6 +154,11 @@ public class JitsiMeetActivity extends AppCompatActivity {
protected void onDestroy() {
super.onDestroy();
if (view != null) {
view.dispose();
view = null;
}
JitsiMeetView.onHostDestroy(this);
}

View File

@ -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);