From a01e3e9d8a631b9869986369c6a254f894b1be55 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sa=C3=BAl=20Ibarra=20Corretg=C3=A9?= Date: Tue, 22 Dec 2020 11:04:34 +0100 Subject: [PATCH] fix(android) avoid crashes if view is null This may happen due to API misuse, but also in complex applications where activity lifetimes are not straightforward. --- .../org/jitsi/meet/sdk/JitsiMeetActivity.java | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) 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 c3ce899c8..01a308b05 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 @@ -107,7 +107,7 @@ public class JitsiMeetActivity extends FragmentActivity protected JitsiMeetView getJitsiView() { JitsiMeetFragment fragment = (JitsiMeetFragment) getSupportFragmentManager().findFragmentById(R.id.jitsiFragment); - return fragment.getJitsiView(); + return fragment != null ? fragment.getJitsiView() : null; } public void join(@Nullable String url) { @@ -119,11 +119,23 @@ public class JitsiMeetActivity extends FragmentActivity } public void join(JitsiMeetConferenceOptions options) { - getJitsiView().join(options); + JitsiMeetView view = getJitsiView(); + + if (view != null) { + view.join(options); + } else { + JitsiMeetLogger.w("Cannot join, view is null"); + } } public void leave() { - getJitsiView().leave(); + JitsiMeetView view = getJitsiView(); + + if (view != null) { + view.leave(); + } else { + JitsiMeetLogger.w("Cannot leave, view is null"); + } } private @Nullable JitsiMeetConferenceOptions getConferenceOptions(Intent intent) { @@ -191,7 +203,11 @@ public class JitsiMeetActivity extends FragmentActivity @Override protected void onUserLeaveHint() { - getJitsiView().enterPictureInPicture(); + JitsiMeetView view = getJitsiView(); + + if (view != null) { + view.enterPictureInPicture(); + } } // JitsiMeetActivityInterface