Ver código fonte

[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.
j8
Saúl Ibarra Corretgé 8 anos atrás
pai
commit
bfa5f4c953

+ 9
- 0
android/README.md Ver arquivo

@@ -56,6 +56,9 @@ public class MainActivity extends AppCompatActivity {
56 56
     protected void onDestroy() {
57 57
         super.onDestroy();
58 58
 
59
+        view.dispose();
60
+        view = null;
61
+
59 62
         JitsiMeetView.onHostDestroy(this);
60 63
     }
61 64
 
@@ -102,6 +105,12 @@ See JitsiMeetView.setWelcomePageEnabled.
102 105
 The `JitsiMeetView` class is the core of Jitsi Meet SDK. It's designed to
103 106
 display a Jitsi Meet conference (or a welcome page).
104 107
 
108
+#### dispose()
109
+
110
+Releases all resources associated with this view. This method MUST be called
111
+when the Activity holding this view is going to be destroyed, usually in the
112
+`onDestroy()` method.
113
+
105 114
 #### getListener()
106 115
 
107 116
 Returns the `JitsiMeetViewListener` instance attached to the view.

+ 5
- 0
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetActivity.java Ver arquivo

@@ -154,6 +154,11 @@ public class JitsiMeetActivity extends AppCompatActivity {
154 154
     protected void onDestroy() {
155 155
         super.onDestroy();
156 156
 
157
+        if (view != null) {
158
+            view.dispose();
159
+            view = null;
160
+        }
161
+
157 162
         JitsiMeetView.onHostDestroy(this);
158 163
     }
159 164
 

+ 16
- 4
android/sdk/src/main/java/org/jitsi/meet/sdk/JitsiMeetView.java Ver arquivo

@@ -199,6 +199,21 @@ public class JitsiMeetView extends FrameLayout {
199 199
         views.add(this);
200 200
     }
201 201
 
202
+    /**
203
+     * Releases the React resources (specifically the {@link ReactRootView})
204
+     * associated with this view.
205
+     *
206
+     * This method MUST be called when the Activity holding this view is destroyed, typically in the
207
+     * {@code onDestroy} method.
208
+     */
209
+    public void dispose() {
210
+        if (reactRootView != null) {
211
+            removeView(reactRootView);
212
+            reactRootView.unmountReactApplication();
213
+            reactRootView = null;
214
+        }
215
+    }
216
+
202 217
     /**
203 218
      * Gets the {@link JitsiMeetViewListener} set on this {@code JitsiMeetView}.
204 219
      *
@@ -257,10 +272,7 @@ public class JitsiMeetView extends FrameLayout {
257 272
 
258 273
         // TODO: ReactRootView#setAppProperties is only available on React
259 274
         // Native 0.45, so destroy the current root view and create a new one.
260
-        if (reactRootView != null) {
261
-            removeView(reactRootView);
262
-            reactRootView = null;
263
-        }
275
+        dispose();
264 276
 
265 277
         reactRootView = new ReactRootView(getContext());
266 278
         reactRootView.startReactApplication(reactInstanceManager, "App", props);

Carregando…
Cancelar
Salvar