[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:
parent
03b043ca2b
commit
bfa5f4c953
|
@ -56,6 +56,9 @@ public class MainActivity extends AppCompatActivity {
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
|
||||||
|
view.dispose();
|
||||||
|
view = null;
|
||||||
|
|
||||||
JitsiMeetView.onHostDestroy(this);
|
JitsiMeetView.onHostDestroy(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,6 +105,12 @@ See JitsiMeetView.setWelcomePageEnabled.
|
||||||
The `JitsiMeetView` class is the core of Jitsi Meet SDK. It's designed to
|
The `JitsiMeetView` class is the core of Jitsi Meet SDK. It's designed to
|
||||||
display a Jitsi Meet conference (or a welcome page).
|
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()
|
#### getListener()
|
||||||
|
|
||||||
Returns the `JitsiMeetViewListener` instance attached to the view.
|
Returns the `JitsiMeetViewListener` instance attached to the view.
|
||||||
|
|
|
@ -154,6 +154,11 @@ public class JitsiMeetActivity extends AppCompatActivity {
|
||||||
protected void onDestroy() {
|
protected void onDestroy() {
|
||||||
super.onDestroy();
|
super.onDestroy();
|
||||||
|
|
||||||
|
if (view != null) {
|
||||||
|
view.dispose();
|
||||||
|
view = null;
|
||||||
|
}
|
||||||
|
|
||||||
JitsiMeetView.onHostDestroy(this);
|
JitsiMeetView.onHostDestroy(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -199,6 +199,21 @@ public class JitsiMeetView extends FrameLayout {
|
||||||
views.add(this);
|
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}.
|
* 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
|
// TODO: ReactRootView#setAppProperties is only available on React
|
||||||
// Native 0.45, so destroy the current root view and create a new one.
|
// Native 0.45, so destroy the current root view and create a new one.
|
||||||
if (reactRootView != null) {
|
dispose();
|
||||||
removeView(reactRootView);
|
|
||||||
reactRootView = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
reactRootView = new ReactRootView(getContext());
|
reactRootView = new ReactRootView(getContext());
|
||||||
reactRootView.startReactApplication(reactInstanceManager, "App", props);
|
reactRootView.startReactApplication(reactInstanceManager, "App", props);
|
||||||
|
|
Loading…
Reference in New Issue